plt.show()不开新图window

plt.show () does not open a new figure window

我正在尝试使用 plt.show () 显示一些图。我得到 IPython 控制台上显示的图,但我需要在新的 window 中查看每个图。我能做什么?

您想在 iPython 控制台中输入 %matplotlib qt。这只会为您所在的会话更改它。要为将来更改它,请转到 Tools > Preferences、select iPython Console > Graphics,然后将 Graphics Backend 设置为 Qt4Qt5。这应该有效。

在你的笔记本中,试试

    import matplotlib.pyplot as plt
    %matplotlib

像这样单独调用,应该在单独的window中给出输出。 %matplotlib 也有几个选项,具体取决于您的系统。要查看所有可用选项,请使用

    %matplotlib -l

通话中

    %matplotlib inline

会在笔记本上重新画图。

其他选项正在使用 plt.figure:

import matplotlib.pyplot as plt
plt.figure(1)                # the first figure
plt.subplot(211)             # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212)             # the second subplot in the first figure
plt.plot([4, 5, 6])
plt.show(block=False)

plt.figure(2)                # a second figure
plt.plot([4, 5, 6])          # creates a subplot(111) by default
plt.show(block=False)

plt.figure(1)                # figure 1 current; subplot(212) still current
plt.subplot(211)             # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
plt.show(block=False)

(参见:https://matplotlib.org/users/pyplot_tutorial.html