我想在 3D 坐标中绘制四个点(或相互连接的线)。并且坐标存储在X,Y和Z中。例如,我有以下几行:
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.matrix('-1, 1, 1, 2')
Y = np.matrix('1, 2, 4, 6')
Z = np.matrix('3, 4, 2, 1')
ax.plot(X, Y, Z)
plt.show()
但是运行后会出现类型错误。我猜这是由于 numpy 中矩阵类型的输入。有人知道如何轻松解决这个问题吗?
错误信息:
Traceback (most recent call last):
File "C:\Users\I077165\Desktop\tmp.py", line 11, in <module>
ax.plot(X, Y, Z)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1312, in plot
lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 3848, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 323, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 284, in _plot_args
raise ValueError, 'third arg must be a format string'
ValueError: third arg must be a format string
谢谢。