python - Pyplot: Shared axes and no space between subplots -
this related (or rather follow-up) new pythonic style shared axes square subplots in matplotlib?.
i want have subplots sharing 1 axis in question linked above. however, want no space between plots. relevant part of 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 result:
if comment out 2 plt.setp() commands, added white borders:
how can make figure first result, axes touching in second result?
edit: fastest way result 1 described @benjamin bannier, use
fig.subplots_adjust(wspace=0)
the alternative make figure has width/height ratio equal 2
(as have 2 plots). may advisable if plan including figure in document, , know columnwidth of final document.
you can set width , height in call figure(figsize=(width,height))
, or 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:
as @benjamin bannier points out, drawback have 0 margins. can play subplot_adjust()
, must careful making space in symmetric way if want keep solution simple. example fig.subplots_adjust(.1,.1,.9,.9,0,0)
.
Comments
Post a Comment