python cannot pickle 'Tensor' object
在pycharm中用matplotlib绘制图像,会报错,代码以及报错信息如下,一直无法解决,请教大家这个该怎么办
代码:
from matplotlib import pyplot as plt # matplotlib 是 Python 的绘图库
plt.rcParams['figure.figsize'] = (8.0, 6.0)
plt.scatter(X_train, y_train, facecolor="none", edgecolor='#e4007f', s=50, label="train data")
#plt.scatter(X_test, y_test, facecolor="none", edgecolor="r", s=50, label="test data")
plt.plot(X_underlying, y_underlying, c='#000000', label=r"$\sin(2\pi x)$")
plt.legend(fontsize='x-large')
plt.savefig('ml-vis2.pdf')
plt.show()
报错信息:
W1110 08:32:06.620424 20492 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 11.6, Runtime API Version: 10.2
W1110 08:32:06.630646 20492 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
Traceback (most recent call last):
File "D:\document wyl\编程自学\pythonProject\2.3多项式回归.py", line 69, in
plt.plot(X_underlying, y_underlying, c='#000000', label=r"$\sin(2\pi x)$")
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\pyplot.py", line 2740, in plot
return gca().plot(
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_axes.py", line 1662, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_base.py", line 311, in
call
yield from self._plot_args(
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_base.py", line 544, in _plot_args
return [l[0] for l in result]
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_base.py", line 544, in
return [l[0] for l in result]
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_base.py", line 537, in
result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\axes
_base.py", line 351, in _makeline
seg = mlines.Line2D(x, y, **kw)
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib
_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\lines.py", line 412, in
init
self.set_data(xdata, ydata)
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\lines.py", line 650, in set_data
self.set_xdata(x)
File "D:\install wyl\program\anaconda\envs\paddle\lib\site-packages\matplotlib\lines.py", line 1279, in set_xdata
self._xorig = copy.copy(x)
File "D:\install wyl\program\anaconda\envs\paddle\lib\copy.py", line 92, in copy
rv = reductor(4)
TypeError: cannot pickle 'Tensor' object
0 提建议
当前问题酬金
¥ 0 (可追加 ¥500)
支付方式
余额支付
余额: ¥ 499
扫码支付
提供问题酬金的用户不参与问题酬金结算和分配
支付即为同意 《付费问题酬金结算规则》