I’m using matplotlib 1.0.1. I have the following simple script to plot a surface:
···
from numpy import linspace, sin, cos, meshgrid
from matplotlib.pyplot import figure, show, xlabel, ylabel
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
n = 35
x = linspace(-5, 5, n)
y = linspace(0, 10, n)
X, Y = meshgrid(x, y)
Z = X*sin(X)cos(0.25Y)
fig = figure()
ax = fig.gca(projection=‘3d’)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.copper)
xlabel(‘x’)
ylabel(‘y’)
show()
It works fine–many thanks to all the folks working on the 3D plots!
But notice that Axes3D is imported from matplotlib.mplot3d, but never explicitly used. If I comment out that import, however, I get the following traceback:
Traceback (most recent call last):
File “surf_demo.py”, line 15, in
ax = fig.gca(projection=‘3d’)
File “/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/figure.py”, line 965, in gca
return self.add_subplot(111, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/figure.py”, line 675, in add_subplot
projection_class = get_projection_class(projection)
File “/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/projections/init.py”, line 61, in get_projection_class
raise ValueError(“Unknown projection ‘%s’” % projection)
ValueError: Unknown projection ‘3d’
Is this expected?
Warren
Yes, the last lines of axes3d.py, which get called when Axes3D is imported, are:
import matplotlib.projections as proj
proj.projection_registry.register(Axes3D)
which is what lets matplotlib know about the '3d' projection. Just
importing the Axes3D module therefore performs the necessary
registration of the projection to be able to use it in subsequent
code. Code analysis tools like rope don't know about this behind the
scenes stuff though, so it looks like a redundant import to them.
Angus.
···
On 27 March 2011 20:47, Warren Weckesser <warren.weckesser@...1036...> wrote:
I'm using matplotlib 1.0.1. I have the following simple script to plot a
surface:
-----
from numpy import linspace, sin, cos, meshgrid
from matplotlib.pyplot import figure, show, xlabel, ylabel
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
n = 35
x = linspace(-5, 5, n)
y = linspace(0, 10, n)
X, Y = meshgrid(x, y)
Z = X*sin(X)*cos(0.25*Y)
fig = figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.copper)
xlabel('x')
ylabel('y')
show()
-----
It works fine--many thanks to all the folks working on the 3D plots!
But notice that Axes3D is imported from matplotlib.mplot3d, but never
explicitly used. If I comment out that import, however, I get the following
traceback:
-----
Traceback (most recent call last):
File "surf_demo.py", line 15, in <module>
ax = fig.gca(projection='3d')
File
"/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/figure.py",
line 965, in gca
return self.add_subplot(111, **kwargs)
File
"/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/figure.py",
line 675, in add_subplot
projection_class = get_projection_class(projection)
File
"/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/projections/__init__.py",
line 61, in get_projection_class
raise ValueError("Unknown projection '%s'" % projection)
ValueError: Unknown projection '3d'
-----
Is this expected?
--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh