下面是一个例子:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# Initialize figure and 3D axis
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Cube data
X = [0, 1, 1, 0, 0, 1, 1, 0]
Y = [0, 0, 1, 1, 0, 0, 1, 1]
Z = [0, 0, 0, 0, 1, 1, 1, 1]
# Plotting cube
ax.plot_wireframe(X, Y, Z)
# Show plot
plt.show()
似乎变量(X, Y, Z)
不起作用,并产生以下错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[53], line 8
6 Z = [0, 0, 0, 0, 1, 1, 1, 1]
7 # Plotting cube
----> 8 ax.plot_wireframe(X, Y, Z)
9 # Show plot
10 plt.show()
File ~\anaconda3\envs\py11\Lib\site-packages\mpl_toolkits\mplot3d\axes3d.py:1731, in Axes3D.plot_wireframe(self, X, Y, Z, **kwargs)
1693 """
1694 Plot a 3D wireframe.
1695
(...)
1727 Other keyword arguments are forwarded to `.Line3DCollection`.
1728 """
1730 had_data = self.has_data()
-> 1731 if Z.ndim != 2:
1732 raise ValueError("Argument Z must be 2-dimensional.")
1733 # FIXME: Support masked arrays
AttributeError: 'list' object has no attribute 'ndim'
如何在线框上绘制这三个列表?
1条答案
按热度按时间q9yhzks01#
错误提示
z.ndim
无效,因为Z
是一个列表。但这是测试Z
是二维的一部分。将
Z
作为一个数组,我们得到2d错误消息:从线框文档: