Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: error plotting z-axis array with np.nan -- does not plot with cmap option (surface plot) #20905

Closed
sbeer3 opened this issue Aug 25, 2021 · 5 comments
Milestone

Comments

@sbeer3
Copy link

sbeer3 commented Aug 25, 2021

Bug summary

The bug I have is that when trying to plot a surface plot, and have some z axis values as np.nan, if the cmap option is included in the construction of the surface plot, the plot shows up as an empty space.
image

Code for reproduction

xx = np.linspace(0.0, 100, 101) 
yy = np.linspace(0.0, 100, 101) 
zz = np.linspace(0.0, 0, 1)
x,y,z = np.meshgrid(xx,yy,zz,indexing='ij')

z[30][30] = np.nan

fig = plt.figure(figsize=(13,13))           
ax = fig.add_subplot(111,projection='3d')
ax.plot_surface(x[:,:,0],y[:,:,0],z[:,:,0], rstride=1, cstride=1, cmap='coolwarm', edgecolor='none') 
#the cmap option causes a blank plot

Actual outcome

image

Expected outcome

The plot should just be a flat surface plot 100 x 100 with a np.nan value at (30,30)

Operating system

Windows 10 / Ubuntu

Matplotlib Version

3.4.2

Matplotlib Backend

No response

Python version

3.8.10

Jupyter version

No response

Other libraries

No response

Installation

pip

Conda channel

No response

@tacaswell
Copy link
Member

This appears to fixed on the default branch and v3.5.x

so

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

xx = np.linspace(0.0, 100, 101)
yy = np.linspace(0.0, 100, 101)
zz = np.linspace(0.0, 0, 1)
x, y, z = np.meshgrid(xx, yy, zz, indexing="ij")

z[30][30] = np.nan

fig = plt.figure(figsize=(13, 13))
ax = fig.add_subplot(111, projection="3d")
ax.plot_surface(
    x[:, :, 0],
    y[:, :, 0],
    z[:, :, 0],
    rstride=1,
    cstride=1,
    cmap="coolwarm",
    edgecolor="none",
)
ax.set_title(f"Matplotlib: {matplotlib.__version__}")
# the cmap option causes a blank plot
plt.show()

You can test out the 3.5 beta release now if you want:

pip install matplotlib --upgrade --pre

@tacaswell tacaswell added this to the v3.5.0 milestone Aug 25, 2021
@tacaswell
Copy link
Member

I am going to close this as fixed.

I do not think we are going to have another 3.4.x release so even if we tracked down the fix for this and backported it (assuming it is a small enough change to backport), we would likely not release it. That said, if someone did the work to track this down we could consider it.

@sbeer3
Copy link
Author

sbeer3 commented Aug 25, 2021

@tacaswell appreciate it

@WeatherGod
Copy link
Member

WeatherGod commented Aug 25, 2021 via email

@tacaswell
Copy link
Member

Ah, then that is definitely not a back-port candidate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants