如何使用canvas(matplotlib)在figure上实现两个绘图?

2024-04-25 14:43:51 发布

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

我想在一个窗口实现两个画布绘图。我需要跑步(x,y,z)。X-Axe保持不变,但是我仍然有一个带有数据z(y-Axe)和数据X(X-Axe)的绘图。我该怎么做?你知道吗

def on_launch(self):
        #Set up plot
        self.figure, self.ax = plt.subplots()
        self.lines, = self.ax.plot([],[], 'o')
        #Autoscale on unknown axis and known lims on the other
        self.ax.set_autoscaley_on(True)
        self.ax.set_xlim(self.min_x, self.max_x)
        #Other stuff
        self.ax.grid()

    def on_running(self, xdata, ydata):
        #Update data (with the new _and_ the old points)
        self.lines.set_xdata(xdata)
        self.lines.set_ydata(ydata)
        #Need both of these in order to rescale
        self.ax.relim()
        self.ax.autoscale_view()
        #We need to draw *and* flush
        self.figure.canvas.draw()
        self.figure.canvas.flush_events()

Tags: andthe数据self绘图plotondef