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

cm.set_bad() not working for specific values of grayscale and dpi when saving as pdf #20575

Closed
@bugalo

Description

@bugalo

Bug report

Bug summary

When modifying a colormap with cm.set_bad( color='0.9' ) and saving the image as pdf, the bad colors appear as green instead of gray. This happens for some data sets (I cannot reproduce it with synthetic data sets, it happens with some of my datasets), with some dpi values (for the attached example, it happens with dpi of 1200, but not with dpi of 1000), with some grayscale values (for the attached example, it doesn't happen with color values of '0.79' or darker), and when saving as pdf (it does not happen when displaying the figure with plt.show()).

This is the dataset used for the example code:Data.csv

Code for reproduction

# Paste your code here##importnumpyasnpimportpandasaspdfromcopyimportcopyfrommatplotlibimportcmfrommatplotlibimportpyplotaspltfig_size_px= (1280,960)fig_dpi=200fig_size_inch=tuple(fi/fig_dpiforfiinfig_size_px )n=1730m=1731data=pd.read_csv('Data.csv',index_col=0,engine='c',dtype=np.float64 ).valuesMask=np.uint8(np.reshape(data[ :,0 ], (m,n ) ) )data=np.reshape(data[ :,1 ], (m,n ) )cmap_jet=copy(cm.jet )cmap_jet.set_bad(color='0.9' )# cmap_jet.set_bad( color='0.78' )# cmap_jet.set_bad( color=(0.9, 0.9, 0.9) )# cmap_jet.set_bad( color='#d8dcd6' )fig4=plt.figure(4,figsize=fig_size_inch,dpi=fig_dpi,facecolor='w',clear=True,tight_layout=True )fig4.clf()ax4=fig4.add_subplot(111,aspect='equal')ax4.cla()data_masked=np.ma.MaskedArray(data,Mask==0 )h4=ax4.imshow(data_masked,origin='lower',cmap=cmap_jet,interpolation='Antialiased' )ax4.get_xaxis().set_visible(False )ax4.get_yaxis().set_visible(False )fig4.savefig('Plot_Bad.pdf',dpi=fig_dpi*6,format='pdf',transparent=True )fig4.savefig('Plot_Good.pdf',dpi=fig_dpi*5,format='pdf',transparent=True )plt.show()

Actual outcome

Plot_Bad.pdf

# If applicable, paste the console output here##

Expected outcome

Plot_Good.pdf

Matplotlib version

  • Operating system: Gentoo Linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.2
  • Matplotlib backend (print(matplotlib.get_backend())): GTK3Agg
  • Python version: 3.9.5
  • Jupyter version (if applicable):
  • Other libraries:

From the distribution repositories

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp