Pyplot: Common axes and free space between subheadings

Is this related (or rather continued) with the new pythonic style for common axes of common axes in matplotlib? .

I want to have subtitles dividing one axis, as in the question related above. However, I also do not want space between the plots. This is an important part of my code:

f, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True) plt.setp(ax1, aspect=1.0, adjustable='box-forced') plt.setp(ax2, aspect=1.0, adjustable='box-forced') # Plot 1 ax1.matshow(pixels1, interpolation="bicubic", cmap="jet") ax1.set_xlim((0,500)) ax1.set_ylim((0,500)) # Plot 2 ax2.matshow(pixels2, interpolation="bicubic", cmap="jet") ax2.set_xlim((0,500)) ax2.set_ylim((0,500)) f.subplots_adjust(wspace=0) 

And this is the result: enter image description here

If I comment on the two plt.setp () commands, I get some added white borders: enter image description here

How can I make the shape look like my first result, but with axes touching as in the second result?

+6
source share
1 answer

EDIT: The fastest way to get your result is the one described by @Benjamin Bannier, just use

 fig.subplots_adjust(wspace=0) 

An alternative is to create a shape with a width / height ratio of 2 (since you have two graphs). This may be advisable only if you plan to include the figure in the document, and you already know the column width of the final document.

You can set the width and height in the call to Figure(figsize=(width,height)) or as the parameter plt.subplots() in inches. Example:

 fig, axes = plt.subplots(ncols=2, sharex=True, sharey=True,figsize=(8,4)) fig.subplots_adjust(0,0,1,1,0,0) 

Screenshot: enter image description here

As @Benjamin Bannier notes, you have zero fields as a disadvantage. You can then play with subplot_adjust() , but you have to be careful when making the space in a symmetrical way if you want the solution to be simple. An example would be fig.subplots_adjust(.1,.1,.9,.9,0,0) .

+5
source

All Articles