错误提示:
使用matplotlib画子图时提示:ValueError: Single argument to subplot must be a three-digit integer, not 3411
Traceback (most recent call last):
File "13-plt-subplot-子图限制.py", line 30, in <module>
ax3 = plt.subplot(3411)
File "D:\Python\Python38\lib\site-packages\matplotlib\pyplot.py", line 1142, in subplot
ax = fig.add_subplot(*args, **kwargs)
File "D:\Python\Python38\lib\site-packages\matplotlib\figure.py", line 1402, in add_subplot
ax = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "D:\Python\Python38\lib\site-packages\matplotlib\axes\_subplots.py", line 39, in __init__
self._subplotspec = SubplotSpec._from_subplot_args(fig, args)
File "D:\Python\Python38\lib\site-packages\matplotlib\gridspec.py", line 666, in _from_subplot_args
raise ValueError(
ValueError: Single argument to subplot must be a three-digit integer, not 3411
错误原因:
1、使用matplotlib的subplot()画子图时,如果是用单个参数表示行列和位置,必须是3位数xyz,z<=x*y,z只用能1~9的数值,不能大于9。
解决方法:
1、上面的第30行代码中subplot方法的入参用3个整数表示,可以改为:
#ax3 = plt.subplot(3411)
ax3 = plt.subplot(3,4,11)
相关内容:
如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。