使用plt.show()时报错 'ValueError: max() arg is an empty sequence'
在Pycharm下使用matploylib库绘制3D图的时候,在最后需要显示图像的时候,每当输入plt.show()
都会报错
ValueError: max() arg is an empty sequence
但是同样的代码在IDLE里面运行就没有问题。
请问是怎么回事儿呢?应该怎么处理才好,非常感谢
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-6 * np.pi, 6 * np.pi, 1000)
y = np.sin(x)
z = np.cos(x)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot(x, y, z)
plt.show()
我试着在 Python Console 里一行一行的运行,都是在最后plt.show()
的时候才会报错
[<mpl_toolkits.mplot3d.art3d.Line3D at 0x111b09c88>]
plt.show()
/Users/harry./Library/Python/3.6/lib/python/site-packages/matplotlib/figure.py:1743: UserWarning: This figure includes Axes that are not compatible with tight_layout, so its results might be incorrect.
warnings.warn("This figure includes Axes that are not "
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-6-1eb00ff78cf2>", line 1, in <module>
plt.show()
File "/Users/harry./Library/Python/3.6/lib/python/site-packages/matplotlib/pyplot.py", line 253, in show
return _show(*args, **kw)
File "/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 27, in __call__
manager.show(**kwargs)
File "/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 99, in show
self.canvas.show()
File "/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 64, in show
self.figure.tight_layout()
File "/Users/harry./Library/Python/3.6/lib/python/site-packages/matplotlib/figure.py", line 1753, in tight_layout
rect=rect)
File "/Users/harry./Library/Python/3.6/lib/python/site-packages/matplotlib/tight_layout.py", line 326, in get_tight_layout_figure
max_nrows = max(nrows_list)
ValueError: max() arg is an empty sequence
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
个人的理解是,IDLE可以展现图片,但是python console(类似与命令行)没有办法展示图片,所以就报错了。
解决方案可以把你要看的文件,以pic.png的形式保存到本地,就不会报错了。
最后一步改成如下: