Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: savefig() behaves strangely with subplots and colorbar when saving as eps #25867

Open
@punyidea

Description

@punyidea

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

good_fig

The figure when saved to eps (converted to pdf for upload)

bad_fig.pdf

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp