NxM subplots, tight, suptitle

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

NxM subplots, tight, suptitle

Heiland, Randy
Any advice for wanting to do a grid of subplots, with fig.tight_layout(), and with "extra” space at the top for a suptitle? As this simple script demonstrates, there isn’t really any space left at the top after doing tight_layout:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,4))
ax0, ax1 = axes.flatten()

fig.tight_layout()
plt.suptitle('This is a somewhat long figure title', y=0.99, fontsize=12)
plt.show()

thanks!
Randy
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: NxM subplots, tight, suptitle

Johann Rohwer
On 16/12/17 23:54, Heiland, Randy wrote:
Any advice for wanting to do a grid of subplots, with fig.tight_layout(), and with "extra” space at the top for a suptitle? As this simple script demonstrates, there isn’t really any space left at the top after doing tight_layout:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,4))
ax0, ax1 = axes.flatten()

fig.tight_layout()
plt.suptitle('This is a somewhat long figure title', y=0.99, fontsize=12)
plt.show()
You can adjust the space individually for left, top, right, and bottom, as well as horizontally and vertically between the subplots, with fig.subplots_adjust().

call signature::

  subplots_adjust(left=None, bottom=None, right=None, top=None,
                  wspace=None, hspace=None)

The parameter meanings (and suggested defaults) are::

  left  = 0.125  # the left side of the subplots of the figure
  right = 0.9    # the right side of the subplots of the figure
  bottom = 0.1   # the bottom of the subplots of the figure
  top = 0.9      # the top of the subplots of the figure
  wspace = 0.2   # the amount of width reserved for blank space between subplots
  hspace = 0.2   # the amount of height reserved for white space between subplots

The actual defaults are controlled by the rc file
File:      /usr/lib/python2.7/dist-packages/matplotlib/pyplot.py
Type:      function



The integrity and confidentiality of this email is governed by these terms / Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings gereël. http://www.sun.ac.za/emaildisclaimer
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: NxM subplots, tight, suptitle

Heiland, Randy

On Dec 17, 2017, at 3:43 AM, Johann Rohwer <[hidden email]> wrote:

On 16/12/17 23:54, Heiland, Randy wrote:
Any advice for wanting to do a grid of subplots, with fig.tight_layout(), and with "extra” space at the top for a suptitle? As this simple script demonstrates, there isn’t really any space left at the top after doing tight_layout:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,4))
ax0, ax1 = axes.flatten()

fig.tight_layout()
plt.suptitle('This is a somewhat long figure title', y=0.99, fontsize=12)
plt.show()
You can adjust the space individually for left, top, right, and bottom, as well as horizontally and vertically between the subplots, with fig.subplots_adjust().

call signature::

  subplots_adjust(left=None, bottom=None, right=None, top=None,
                  wspace=None, hspace=None)

The parameter meanings (and suggested defaults) are::

  left  = 0.125  # the left side of the subplots of the figure
  right = 0.9    # the right side of the subplots of the figure
  bottom = 0.1   # the bottom of the subplots of the figure
  top = 0.9      # the top of the subplots of the figure
  wspace = 0.2   # the amount of width reserved for blank space between subplots
  hspace = 0.2   # the amount of height reserved for white space between subplots

The actual defaults are controlled by the rc file
File:      /usr/lib/python2.7/dist-packages/matplotlib/pyplot.py
Type:      function



The integrity and confidentiality of this email is governed by these terms / Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings gereël. http://www.sun.ac.za/emaildisclaimer
_______________________________________________


Thanks very much, Johann. I’d actually played around with subplots_adjust previously and gave up. However, your email nudged me back to it and I do indeed have pretty good results now. And for the record, one would use this *instead* of the tight_layout, not in addition to it.

Randy
 


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users