如何解决在已显示的多个图形上更新图和子图
我有一个 GUI,我有一个数据表来放置值,可以选择将数据绘制为折线图,它在同一图中显示原始数据和一阶导数,但单独的子图都包含在像这样的滚动区域:Example graphs。我可以分析数据表中的数据并将其吐出到结果表中,但我想获取其中一些结果并在图表上以标记(垂直线)的形式在某些点直观地显示出来。我可以让标记随心所欲地出现,但它们都出现在最后一个图的最后一个子图上。我在识别代码并将其指向特定地块时遇到问题。这是我拥有的相关代码:
def populate_graphs(self):
self.widgets = []
self.graph_widget = QtWidgets.QWidget()
self.scroll_layout = QtWidgets.QVBoxLayout()
self.graph_widget.setLayout(self.scroll_layout)
lay = QtWidgets.QVBoxLayout()
self.scroll_layout.addLayout(lay)
self.scroll_layout.addStretch()
df = self.readDataTable(self.datatable)
if not df.empty:
plt.close('all')
sample_name = df.columns
count = self.smooth_repeat
sd_df = self.deriv(df)
while count > 0:
sd_df = self.smooth(sd_df)
count -= 1
for i in range(len(df.columns)):
if i > 0:
self.canvaswidget = GraphWidget(sample_name[i])
self.canvaswidget.setMinimumSize(250,400)
self.widgets.append(self.canvaswidget)
lay.addWidget(self.canvaswidget)
plt.ion()
plt.subplot(2,1,1)
plt.plot(df.iloc[:,0],df.iloc[:,i])
plt.title(sample_name[i])
plt.xlabel(sample_name[0])
plt.ylabel("OD")
plt.subplot(2,2)
plt.plot(sd_df.iloc[:,sd_df.iloc[:,i])
plt.title("{0} Rate".format(sample_name[i]))
plt.xlabel(sample_name[0])
plt.ylabel("OD/min")
plt.tight_layout()
self.graphdisplay.setWidget(self.graph_widget)
self.graphdisplay.setContextMenuPolicy(Qt.CustomContextMenu)
self.graphdisplay.customContextMenuRequested.connect(self.graphMenuEvent)
#Tell it to ignore the max figure open message
plt.rcParams.update({'figure.max_open_warning': 0})
def graphAdd(self):
data = self.readResultsTable(self.resultstable)
names = []
count = 0
colors1 = ['g','r']
if not data.empty:
data_s = data.loc[["Start Time","End Time"]]
names = data_s.index.values.tolist()
for n in data_s.columns:
for xc,i,c in zip(data_s.iloc[:,count],names,colors1):
#self.canvaswidget.n.clear()
#plt.subplot(2,1)
#plt.axvline(x=xc,label=i,c=c)
#plt.legend()
#plt.subplot(2,2)
plt.axvline(x=xc,c=c)
plt.legend()
self.canvaswidget.n.canvas.draw()
self.canvaswidget.n.canvas.flush_events()
count += 1
#making the graph widget
class GraphWidget(QtWidgets.QWidget):
def __init__(self,name,*args,**kwargs):
super(GraphWidget,self).__init__(*args,**kwargs)
self.name = name
names = [self.name]
for n in names:
self.n = plt.figure()
self.axes = self.n.add_subplot(111)
self.canvas = FigureCanvas(self.n)
self.toolbar = NavigationToolbar(self.canvas,self)
self.graph_layout = QtWidgets.QVBoxLayout()
self.name_label = QtWidgets.QLabel(self.name)
self.graph_layout.addWidget(self.name_label)
self.graph_layout.addWidget(self.toolbar)
self.graph_layout.addWidget(self.canvas)
self.setLayout(self.graph_layout)
我尝试添加 plt.subplot() 以告诉它向两个子图添加标记(如代码中所见,但已注释掉),这有效,但我收到了两个子图的 MatplotlibDeprecationWarning 消息。除此之外,这仍然只是在最后一个数字上添加标记。为了清除原始轴,以防止出现弃用消息,我添加了 .clear(),但这删除了绘图,而不是轴。
为了识别特定数字,我添加了一个 for 循环以通过数据集名称指定每个数字,但我不确定它是否真的按照我希望的方式工作,或者是否只是将它们全部命名为 self. n.不知道如何检查。总结:如何确定特定数字以针对它们进行更新?奖励:如何在不弃用 matplotlib 的情况下更新它们?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。