python - Matplotlib 小部件中的多个图

标签 python graph matplotlib pyqt qt-designer

我设计了一个相对较大的应用程序,但在实现 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/

相关文章:

java - 如何使用 graph() 或 tograph() 在 WEKA 中显示决策树的图形(ascii 文本图形)表示

javascript - 如何使用多个字符串数据绘制谷歌折线图

python - 在 Matplotlib 中水平对齐两个 Y 轴的 Y 标签

python - 批量插入到 Azure SQL 且 SQLAlchemy 不持久

algorithm - 在有向图中找到其他顶点可达的最小顶点数

python - 调整一幅图像的曝光/白平衡以匹配另一幅图像(使用 PIL?)

python - pandas numpy matplotlib 溢出错误 : date value out of range

python - 按列对 pandas 数据帧进行阈值化

python - 如何修复属性错误: module 'collections' has no attribute 'MutableSequence'

python - 如何在 Python 中用另一个数组替换数组的每个元素?