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

pcolormesh: masked parts of array render black when saving to PDF with Gouraud shading #11769

Closed
@alphaparrot

Description

@alphaparrot

Bug report

If a 2D numpy array has NaNs (thereby interpreted by pcolormesh as masked), and pcolormesh is used to plot the array with Gouraud shading, then when saving to a PDF, instead of rendering those cells as transparent (making anything underneath visible), the cells in question are rendered as black. This does not happen with rasterized plots, plots saved to PNG, or plots displayed interactively. This appears to be independent of backend. Simply using imshow is not an option if the data to be plotted is on a non-uniform grid.

Code for reproduction

importnumpyasnpimportmatplotlib.pyplotaspltx,y=np.meshgrid(np.linspace(0.,100.),np.linspace(0.,100.))map1=np.sin(2*np.pi*x/100.)*np.sin(2*np.pi*y/100.)map2=x*ymap2[20:30,20:30]=np.nan# Plot with Gouraud shading and write to PDFplt.pcolormesh(x,y,map1,shading='Gouraud',cmap='magma')plt.pcolormesh(x,y,map2,shading='Gouraud',cmap='viridis',vmin=np.nanmin(map2),vmax=np.nanmax(map2))plt.savefig("mwe_gouraud.pdf",bbox_inches='tight')# Plot with no shading and write to PDFplt.pcolormesh(x,y,map1,shading='Gouraud',cmap='magma')plt.pcolormesh(x,y,map2,cmap='viridis',vmin=np.nanmin(map2),vmax=np.nanmax(map2))plt.savefig("mwe_noshading.pdf",bbox_inches='tight')# Plot with Gouraud shading and write to PNGplt.pcolormesh(x,y,map1,shading='Gouraud',cmap='magma')plt.pcolormesh(x,y,map2,shading='Gouraud',cmap='viridis',vmin=np.nanmin(map2),vmax=np.nanmax(map2))plt.savefig("mwe_gouraud.png",bbox_inches='tight')

Actual outcome

With Gouraud shading, written to PDF:
Output with Gouraud shading to PDF

Without Gouraud shading, written to PDF:
Output with no shading to PDF

With Gouraud shading, written to PNG:
Output with Gouraud shading to PNG

Expected outcome

All three outputs should show map1 in the central rectangle where values have been set to np.nan (i.e. the masked values should be transparent).

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 2.2.2
  • Matplotlib backend: All
  • Python version: 2.7.9
  • Jupyter version (if applicable): N/A
  • Other libraries: NumPy 1.14.1

matplotlib installed via pip

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