Python错误集锦:subplot提示ValueError: Single argument to subplot must be a three-digit integer, not 3411

原文链接:http://www.juzicode.com/archives/2498

错误提示:

使用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) 
posted @ 2020-12-18 19:47  桔子code  阅读(924)  评论(0编辑  收藏  举报