From: Warren W. <war...@en...> - 2011-03-28 00:48:20
|
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? Warren |
From: Angus M. <am...@gm...> - 2011-03-28 01:25:37
|
On 27 March 2011 20:47, Warren Weckesser <war...@en...> 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? 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. -- AJC McMorland Post-doctoral research fellow Neurobiology, University of Pittsburgh |
From: Warren W. <war...@en...> - 2011-03-28 02:23:48
|
On Sun, Mar 27, 2011 at 8:25 PM, Angus McMorland <am...@gm...> wrote: > On 27 March 2011 20:47, Warren Weckesser <war...@en...> > 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? > > 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. > OK, thanks. Warren > > Angus. > -- > AJC McMorland > Post-doctoral research fellow > Neurobiology, University of Pittsburgh > |