I am testing code I found on matplotlib (https://matplotlib.org/gallery/mplot3d/subplot3d.html?highlight=matplotlib%20pyplot%20plot) to test 3d graphs I added this line ->
import matplotlib
matplotlib.use('PS') # generate postscript output by default
before
import matplotlib.pyplot as plt
to fix a RunTimeError when I compile the program
edit: if I run without those two lines i get this error
However, the program runs but does not show me the graphs. I have looked in lots of places and cannot find the fix for it
im working with virtualenv
pip list:
cycler (0.10.0)
matplotlib (2.1.2)
numpy (1.14.1)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.1)
pytz (2018.3)
setuptools (38.5.1)
six (1.11.0)
wheel (0.30.0)
help please
Edit: code (but also in link)
import matplotlib #added this from matplotlib and compiled
matplotlib.use('PS') # generate postscript output by default
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D, get_test_data
from matplotlib import cm
import numpy as np
# set up a figure twice as wide as it is tall
fig = plt.figure(figsize=plt.figaspect(0.5))
#===============
# First subplot
#===============
# set up the axes for the first plot
ax = fig.add_subplot(1, 2, 1, projection='3d')
# plot a 3D surface like in the example mplot3d/surface3d_demo
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
fig.colorbar(surf, shrink=0.5, aspect=10)
#===============
# Second subplot
#===============
# set up the axes for the second plot
ax = fig.add_subplot(1, 2, 2, projection='3d')
# plot a 3D wireframe like in the example mplot3d/wire3d_demo
X, Y, Z = get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
plt.show()