Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Description
Bug summary
I useimshow()
withcolorbar
andinset_axes
to zoom into the image. After saving the pdf withsavefigure()
andbbox_inches='tight'
the colorbar is shifted.
Very similar to bug#25176, which has already been fixed.
The problem only occurs when using thebbox_inches='tight'
option in combination withinset_axes
.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.cbookascbookimportmatplotlib.cmascmfrommatplotlib.patchesimportPathPatchfrommatplotlib.pathimportPathnp.random.seed(19680801)delta=0.025x=y=np.arange(-3.0,3.0,delta)X,Y=np.meshgrid(x,y)Z1=np.exp(-X**2-Y**2)Z2=np.exp(-(X-1)**2- (Y-1)**2)Z= (Z1-Z2)*2fig,ax=plt.subplots()im=ax.imshow(Z,interpolation='bilinear',cmap=cm.RdYlGn,origin='lower',extent=[-3,3,-3,3],vmax=abs(Z).max(),vmin=-abs(Z).max())cb=plt.colorbar(mappable=im)plt.show()axins=inset_axes(ax,width='20%',height='20%',loc='upper right')Z2=axins.imshow(Z,interpolation='bilinear',cmap=cm.RdYlGn,origin='lower',extent=[-3,3,-3,3],vmax=abs(Z).max(),vmin=-abs(Z).max())x1,x2,y1,y2=-1,0,0,1axins.set_xlim(x1,x2)axins.set_ylim(y1,y2)rectpatch,connects=ax.indicate_inset_zoom(axins,edgecolor='k',alpha=1,lw=1)connects[0].set_visible(False)connects[1].set_visible(True)connects[2].set_visible(True)connects[3].set_visible(False)fig.savefig("temp.pdf",bbox_inches='tight',transparent=True,format="pdf")
Actual outcome
Expected outcome
Somthing like this:
but with tight layout
Additional information
Python version :
Matplotlib version:
Operating system
OS: Linux Fedora 37 (Workstation Edition)
Matplotlib Version
3.8.0
Matplotlib Backend
module://ipympl.backend_nbagg
Python version
3.11.5
Jupyter version
module://ipympl.backend_nbagg
Installation
pip
Metadata
Metadata
Assignees
Labels
No labels