plt.show()没有打开新的图形风

2024-06-24 12:18:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用plt.show()来显示一些图。我得到了IPython控制台上显示的图,但是我需要在一个新窗口中看到每个图。我能做什么?


Tags: showipythonplt试图用
3条回答

在你的笔记本里,试试

    import matplotlib.pyplot as plt
    %matplotlib

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

    %matplotlib -l

呼叫

    %matplotlib inline

将再次在笔记本中绘制绘图。

您想在iPython控制台中键入%matplotlib qt。这只会更改您正在进行的会话。要在将来更改它,请转到Tools > Preferences,选择iPython Console > Graphics,然后将Graphics Backend设置为Qt4Qt5。这应该管用。

另一个选项是使用plt。图:

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

相关问题 更多 >