是否可以有多个PyPlot窗口?还是我仅限于子图? [英] Is it possible to have multiple PyPlot windows? Or am I limited to subplots?

查看:111
本文介绍了是否可以有多个PyPlot窗口?还是我仅限于子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何更清楚地表达我的问题.基本上,PyPlot是否限于一个实例/窗口?我尝试执行的任何破解或变通办法要么导致程序冻结,要么使第二个pyplot窗口进入队列,直到第一个关闭.

I'm not sure how to word my question more clearly. Basically, is PyPlot limited to one instance/window? Any hack or workaround I try either causes my program to freeze or for the second pyplot window to be queued until the first one is closed.

推荐答案

当然,只需打开一个新图形:

Sure, just open a new figure:

import matplotlib.pyplot as plt

plt.plot(range(10))

plt.figure()
plt.plot(range(10), 'ro-')

plt.figure(), plt.plot(...)

plt.show() # only do this once, at the end

如果您在默认的python解释器中运行此命令,则此命令将无效,因为每个图形都需要输入gui的mainloop.如果要在交互式shell中运行事物,请查看IPython.但是,如果您只是正常运行此程序(即将其放入文件中并调用python filename.py),它将可以正常工作.

If you're running this in the default python interpreter, this won't work, as each figure needs to enter the gui's mainloop. If you want to run things in an interactive shell, look into IPython. If you just run this normally (i.e. put it into a file and call python filename.py) it will work fine, though.

这篇关于是否可以有多个PyPlot窗口?还是我仅限于子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆