【发布时间】:2020-08-15 05:59:47
【问题描述】:
所以我有一个非常基本的绘图布局,如下所述(为简洁起见,更改了 x 和 y 值):
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import numpy as np
figure = Figure()
axes = figure.gca()
axes.set_title(‘My Plot’)
x=np.linspace(1,10)
y=np.linspace(1,10)
y1=np.linspace(11,20)
axes.plot(x,y,’-k’,label=‘first one’)
axes.plot(x,y1,’-b’,label=‘second one’)
axes.legend()
axes.grid(True)
我在 QT 设计器中设计了一个 GUI,它有一个 GraphicsView(命名为 graphicsView_Plot),我想把这个图放进去,我想知道我将如何把这个图放到 GraphicsView 中。除非重新开始并使用基于 QT 的绘图功能,否则我真的不知道如何(如果可能)将 matplotlib 图放入此图形视图。我知道如果我也可以将其转换为 QGraphicsItem 将是一件超级简单的事情,因此直接将其放入 GraphicsView 或将其转换为 QGraphicsItem 都对我有用。
【问题讨论】:
-
将 Matplotlib 的画布(它本身就是一个小部件)嵌入到 Qt 应用程序中可能更容易 - 看看示例代码 here。
标签: python matplotlib pyqt