-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Labels
Milestone
Description
Bug report
Bug summary
When running the code below to plot the surface for the equation 1 - y/x, the plot works but I get an error and the rendering of the surface breaks when viewed from some angles.
Code for reproduction
import math
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
# Generate the data
x = np.linspace(-1.0, 1.0, 50)
y = np.linspace(-1.0, 1.0, 50)
z = np.zeros(len(x))
x,y = np.meshgrid(x,y)
z = 1 - y/x
z[z >= 5.0] = 5.0 # Clips top of surface
z[z <= -5.0] = -5.0 # Clips bottom of surface
# place NaNs at the discontinuity
pos = np.where(np.abs(np.diff(z)) >= 5.0)
z[pos] = np.nan
# Create the plot
p1 = plt.figure()
ax = p1.gca(projection='3d')
surf = ax.plot_surface(x,y,z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0,
vmin=np.nanmin(z), vmax=np.nanmax(z), antialiased=False)
plt.title("1 - y/x")
ax.set_xlim(-1.0, 1.0)
ax.set_ylim(-1.0, 1.0)
ax.set_zlim(-5.0, 5.0)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
p1.show()
raw_input("Press any key to close all plots: ")
Actual outcome
/usr/lib/pymodules/python2.7/matplotlib/colors.py:576: RuntimeWarning: invalid value encountered in less
cbook._putmask(xa, xa < 0.0, -1)
Odd rendering issues appear:
Expected outcome
I'd expect to not get errors and to not see the rendering issue. I am using older versions of virtually everything, and this may be a platform-specific issue. Or I may be using this code in a way it was not intended to be used, in which case if there is a more-correct way to do this I'd appreciate someone showing me how to do it.
Matplotlib version
- Operating system: Ubuntu 14.04
- Matplotlib version: 1.3.1
- Matplotlib backend (
print(matplotlib.get_backend())
): 'TkAgg' - Python version: 2.7.6
- Jupyter version (if applicable): N/A
- Other libraries: