Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
pyplot is adding an extra white rectangle to the image, which overlaps with the colorbar. Found when the image has multiple subplots, and only when .eps is used as the format and we use usetex.
Code for reproduction
importmatplotlib.pyplotaspltimportosimportnumpyasnpimportmatplotlibdefsave_plot_out(f:plt.Figure,fig_name,fmt=".eps"):fig_full_name=fig_name+fmtf.savefig(fig_full_name)defsetup_latex():''' from https://web.archive.org/web/20230124103712/https://stackoverflow.com/questions/36671901/matplotlib-savefig-with-usetex-true '''# LaTeX setup# plt.rcParams['text.latex.preamble'] = r'\usepackage{mathptmx}' # load times roman font# plt.rcParams['font.family'] = 'serif' # use serif font as defaultplt.rcParams['text.usetex']=True# enable LaTeX rendering globally# modified from stackoverflow: https://stackoverflow.com/a/39938019defmake_fig():# from mpl_toolkits.axes_grid1 import make_axes_locatabledefmake_subplot(ax):#divider = make_axes_locatable(ax)#cax = divider.append_axes('right', size='5%', pad=0.05)im=ax.imshow(data,cmap='bone')plt.colorbar(im)#fig.colorbar(im, cax=cax, orientation='vertical')data=np.arange(100,0,-1).reshape(10,10)fig,axs=plt.subplots(1,2)make_subplot(axs[0])data=101-datamake_subplot(axs[1])returnfigsetup_latex()fig_made=make_fig()save_plot_out(fig_made,'good_fig',fmt='.png')save_plot_out(fig_made,'bad_fig',fmt='.eps')
Actual outcome
The figure when saved to png
The figure when saved to eps (converted to pdf for upload)
Expected outcome
The colorbars in both figures are identical and appear entirely.
Additional information
No response
Operating system
Ubuntu
Matplotlib Version
3.5.2 and 3.7.1
Matplotlib Backend
Tkagg
Python version
3.8.10
Jupyter version
No response
Installation
None