Acabo de instalar matplotlib y estoy tratando de ejecutar uno de sus scripts de ejemplo. Sin embargo, me encuentro con el error detallado a continuación. ¿Qué estoy haciendo mal?
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z, 16, extend3d=True)
ax.clabel(cset, fontsize=9, inline=1)
plt.show()
El error es
Traceback (most recent call last):
File "<string>", line 245, in run_nodebug
File "<module1>", line 5, in <module>
File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 945, in gca
return self.add_subplot(111, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 677, in add_subplot
projection_class = get_projection_class(projection)
File "C:\Python26\lib\site-packages\matplotlib\projections\__init__.py", line 61, in get_projection_class
raise ValueError("Unknown projection '%s'" % projection)
ValueError: Unknown projection '3d'
python
matplotlib
rectángulo
fuente
fuente

Respuestas:
En primer lugar, creo que
mplot3Dtrabajó un poco diferente enmatplotlibla versión0.99que lo hace en la versión actual dematplotlib.¿Qué versión está utilizando? (Intenta ejecutar:
python -c 'import matplotlib; print matplotlib."__version__")Supongo que está ejecutando la versión
0.99, en cuyo caso deberá usar una sintaxis ligeramente diferente o actualizar a una versión más reciente dematplotlib.Si está ejecutando la versión
0.99, intente hacerlo en lugar de usar elprojectionargumento de la palabra clave:Esto debería funcionar
matplotlib1.0.xtambién, no solo0.99.fuente
from mpl_toolkits.mplot3d import Axes3D. Luego, debería funcionar.python -c 'import matplotlib; print(matplotlib.__version__)'2.0.2?from mpl_toolkits.mplot3d import Axes3D... :)Solo para agregar a la respuesta de Joe Kington (no hay suficiente reputación para un comentario) hay un buen ejemplo de la mezcla de gráficos en 2D y 3D en la documentación en http://matplotlib.org/examples/mplot3d/mixed_subplots_demo.html que muestra proyección = ' 3d 'trabajando en combinación con la importación Axes3D.
De hecho, mientras la importación Axes3D esté presente, la línea
como lo usa el OP también funciona. (marcado con matplotlib versión 1.3.1)
fuente
ax = fig.gca(projection='3d')funciona para mi En lugar deax = plt.subplot(111,projection="3d"). Estoy usando la versión de2.1.0Importe mplot3d entero para usar "proyección = '3d'".
Inserte el siguiente comando en la parte superior de su secuencia de comandos. Debería funcionar bien.
fuente
Me encuentro con el mismo problema, y la respuesta de @Joe Kington y @ bvanlew resuelve mi problema.
pero debería agregar más información cuando usas pycharm y habilitas
auto import.cuando formatea el código, el código
from mpl_toolkits.mplot3d import Axes3Dse eliminará automáticamente mediante pycharm.entonces mi solución es
y funciona bien!
fuente
# noinspection PyUnresolvedReferencesantes de la importación.Prueba esto:
fuente