我设计了一个相对较大的应用程序,但在实现 Matplotlibwidget 图形时遇到了问题。这是我处理图表的代码片段。
以下代码仅绘制 x2 和 y2 的最新图。
注意:这里self.GraphWidget是一个使用QtDesigner实现的MatplotlibWidget对象
def Toggled(self,CD):
self.GraphWidget.axes.plot(self.x1,self.y1,label='plot1')
self.GraphWidget.axes.plot(self.x2,self.y2,label='plot2')
self.GraphWidget.axes.set_xscale('log')
self.GraphWidget.legend()
self.GraphWidget.draw()
以下代码(见下文)在图表上绘制了两条曲线,但我宁愿使用上述方法,以便我可以为每条曲线提供单独的标签等:
def Toggled(self,CD):
self.GraphWidget.axes.plot(self.x1,self.y1,self.x2,self.y2)
self.GraphWidget.axes.set_xscale('log')
self.GraphWidget.legend()
self.GraphWidget.draw()
最佳答案
尝试显式设置保持:
self.GraphWidget.axes.hold(True)
self.GraphWidget.axes.plot(self.x1,self.y1,label='plot1')
self.GraphWidget.axes.plot(self.x2,self.y2,label='plot2')
关于python - Matplotlib 小部件中的多个图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18257509/