如何在一个窗口中显示 matplotlib 图 [英] How to show matplotlib plot in one window
本文介绍了如何在一个窗口中显示 matplotlib 图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个窗口中显示一个绘图,而不是每次运行 PyQT 脚本时都打开另一个窗口.
I want to show a plot in one window instead of opening another window every time I run my PyQT Script.
这是我的代码:
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, aspect='equal')
ax2.add_patch(
patches.Circle(
(x1, y1),
r1,
fill=False
)
)
ax2.add_patch(
patches.Circle(
(x2, y2),
r2,
fill=False
)
)
ax2.add_patch(
patches.Circle(
(x3, y3),
r3,
fill=False
)
)
plt.plot([x_centroid], [y_centroid], 'ro')
plt.show()
每当我更改变量时,都会弹出新窗口.我希望它在 1 个窗口中.
Whenever I change my variables,new window pops up.I want it in 1 window.
推荐答案
据我所知,一旦它开始在该进程中运行另一个脚本,就没有简单的方法来连接到现有的python进程.
As far as I know there is no easy way to connect to an existing python process once it is started to run another script within this process.
您可以选择在交互式会话中工作,例如在IPython中.在那里你可以创建你的情节并在你前进时对其进行操纵.
The option you have is to work in an interactive session, e.g. within IPython. There you may create your plot and manipulate it as you advance.
例如
1: import matplotlib.pyplot as plt
2: import numpy as np
3: fig, ax = plt.subplots()
4: line, = ax.plot([1,3,2])
5: plt.ion()
6: plt.show() # shows the figure
7: line2, = plt.plot([2,2,1]) # inside the figure shows another line
8: line.remove() # removes the first line from the figure
这篇关于如何在一个窗口中显示 matplotlib 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文