Python错误集锦: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) 

相关内容:

数据可视化~matplotlib显示多个子图


关注微信公众号:“桔子code”,欢迎后台留言撩我,我会尽我所能为你解惑Python,C等编程知识

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注