Python 3.x Python matplotlib.pyplot不显示图形

Python 3.x Python matplotlib.pyplot不显示图形,python-3.x,matplotlib,Python 3.x,Matplotlib,我的问题是: 我正在学习python。我正在尝试显示一个带有4个子图的图 第一次使用plt.show(),我得到了我的数字。第二次,我什么也没有得到 有人知道为什么以及如何解决这个问题吗 这是我的密码: >>> import seaborn as sns >>> import matplotlib.pyplot as plt >>> anscombe = sns.load_dataset("anscombe") >>>

我的问题是:

我正在学习python。我正在尝试显示一个带有4个子图的图

第一次使用
plt.show()
,我得到了我的数字。第二次,我什么也没有得到

有人知道为什么以及如何解决这个问题吗

这是我的密码:

>>> import seaborn as sns
>>> import matplotlib.pyplot as plt

>>> anscombe = sns.load_dataset("anscombe")

>>> dataset_1 = anscombe[anscombe['dataset'] == 'I']
>>> dataset_2 = anscombe[anscombe['dataset'] == 'II']
>>> dataset_3 = anscombe[anscombe['dataset'] == 'III']
>>> dataset_4 = anscombe[anscombe['dataset'] == 'IV']

>>> fig = plt.figure()
>>> axes1 = fig.add_subplot(2,2,1)
>>> axes2 = fig.add_subplot(2,2,2)
>>> axes3 = fig.add_subplot(2,2,3)
>>> axes4 = fig.add_subplot(2,2,4)
>>> axes1.plot(dataset_1['x'], dataset_1['y'], 'o')
[<matplotlib.lines.Line2D object at 0x000002088592D8D0>]
>>> axes2.plot(dataset_2['x'], dataset_2['y'], 'o')
[<matplotlib.lines.Line2D object at 0x000002088592DE80>]
>>> axes3.plot(dataset_3['x'], dataset_3['y'], 'o')
[<matplotlib.lines.Line2D object at 0x0000020885941A58>]
>>> axes4.plot(dataset_4['x'], dataset_4['y'], 'o')
[<matplotlib.lines.Line2D object at 0x0000020885941A20>]

>>> plt.show()
>>> plt.show()
>导入seaborn作为sns
>>>将matplotlib.pyplot作为plt导入
>>>anscombe=sns.load_数据集(“anscombe”)
>>>dataset_1=anscombe[anscombe['dataset']=='I']
>>>dataset_2=anscombe[anscombe['dataset']=='II']
>>>数据集_3=anscombe[anscombe['dataset']=='III']
>>>dataset_4=anscombe[anscombe['dataset']=='IV']
>>>图=plt.图()
>>>axes1=图add_子批次(2,2,1)
>>>axes2=图add_子批次(2,2,2)
>>>axes3=图添加子批次(2,2,3)
>>>axes4=图add_子批次(2,2,4)
>>>axes1.plot(数据集_1['x'],数据集_1['y'],'o')
[]
>>>axes2.plot(数据集_2['x'],数据集_2['y'],'o')
[]
>>>axes3.plot(数据集_3['x'],数据集_3['y'],'o')
[]
>>>axes4.plot(数据集_4['x'],数据集_4['y'],'o')
[]
>>>plt.show()
>>>plt.show()
编辑: 我已经搜索了其他帖子,但它们没有帮助我。我特别搜索的是这个:

我在这里和这里做了一些研究

以下是我学到的:

  • 有交互和非交互模式
  • 在使用交互模式时,不要关闭它,因为它会在内存中被完全擦除。让图形保持打开状态,它将随着绘制更多线或对其执行任何操作而更新
  • 在使用非交互式模式时,您可以绘制任意多条线,但只要调用
    show()
    方法,内存中的所有内容都会被擦除,您必须重新打印,然后调用
    show()
    方法立即绘制所有内容
  • 使用非交互模式和
    show()
    方法时,所有命令都会停止,直到图形关闭
  • 当前没有一种解决方案可以显示图形,然后在不重新填充相同行的情况下重新显示
  • 您应该检查默认模式是什么,交互式还是非交互式
  • 要转换为交互模式,请使用
    matplotlib.pyplot.ion()
    方法
  • 要使用非交互模式,请使用
    matplotlib.pyplot.ioff()

  • 我已经解决了我的问题。

    可能是我编辑的文章的重复,你发布的链接对我没有帮助,因为我仍然不知道如何解决这个问题。