ValueError in matplotlib



我正在尝试从数组p绘制3D图。但是,我有一个错误。它的原因是什么,我该如何克服?

代码

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
x=p[:, 0]
y=p[:, 1],
z=p[:, 2], 
ax.plot(x, y, z)
ax.legend()
plt.show()

错误

Traceback (most recent call last):
  File "<ipython-input-51-6e9ef1b4241b>", line 11, in <module>
    ax.plot(x, y, z)
  File "C:UsersRamdayalAnaconda3libsite-packagesmpl_toolkitsmplot3daxes3d.py", line 1537, in plot
    lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)
  File "C:UsersRamdayalAnaconda3libsite-packagesmatplotlib__init__.py", line 1897, in inner
    return func(ax, *args, **kwargs)
  File "C:UsersRamdayalAnaconda3libsite-packagesmatplotlibaxes_axes.py", line 1406, in plot
    for line in self._get_lines(*args, **kwargs):
  File "C:UsersRamdayalAnaconda3libsite-packagesmatplotlibaxes_base.py", line 407, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "C:UsersRamdayalAnaconda3libsite-packagesmatplotlibaxes_base.py", line 360, in _plot_args
    raise ValueError('third arg must be a format string')
ValueError: third arg must be a format string

您将 yz定义为元组: y = something,将导致 (something, ),而您确实希望没有逗号的y = something

x=p[:, 0]
y=p[:, 1]  #remove comma
z=p[:, 2]  #remove comma
ax.plot(x, y, z)

相关内容

  • 没有找到相关文章