如何在一个窗口中显示matplotlib图

时间:2018-01-24 11:01:58

标签: python-3.x matplotlib

我想在一个窗口中显示一个情节,而不是每次运行PyQT脚本时都打开另一个窗口。

这是我的代码:

        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个窗口中显示它。

1 个答案:

答案 0 :(得分:0)

据我所知,一旦现有的python进程开始在此进程中运行另一个脚本,就可以轻松连接到现有的python进程。

您拥有的选项是在互动会话中工作,例如在IPython中。在那里你可以创建你的情节并在你前进时操纵它。

例如

   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
相关问题