使用Python的多个列的实时数据框架的图动态图
我正在尝试使用实时数据绘制动态图。 以下是示例数据框,其中每30秒钟后我想添加我从其他功能收集的数据。
动态数据帧
TIME CE_15750 CE_15800 CE_15850 CE_15900 CE_15950 PE_16000 PE_16050 PE_16100 PE_16150 PE_16200 PE_16250
0 18:54 -5146 -58520 -22849 -78925 -20435 59348 10805 5877 -22 2182 519
1 18:55 -20435 -30990 37085 108 -4634 13528 27239 64451 46905 83803 815
我正在尝试以下代码以绘制图形,但它也没有给出预期的输出
def draw_method():
while True:
plt.cla()
temp_var = live_data()
final_dataframe = pd.DataFrame(temp_var)
final_dataframe.set_index('TIME').plot(figsize = (10,5),grid=True)
plt.gcf()
plt.show()
sleep(30) #30 seconds sleep to add updated data field in dataframe
,我如何为具有 ce _ 和单颜色的所有列提供单一颜色和 pe _ 在图中?我得到的图表的每行都有不同的颜色。
非常感谢您的帮助
I'm trying to plot dynamic graph with live data.
Below is sample dataframe in which after every 30 seconds I want to add data which I'm collecting from other function.
Dynamic DataFrame
TIME CE_15750 CE_15800 CE_15850 CE_15900 CE_15950 PE_16000 PE_16050 PE_16100 PE_16150 PE_16200 PE_16250
0 18:54 -5146 -58520 -22849 -78925 -20435 59348 10805 5877 -22 2182 519
1 18:55 -20435 -30990 37085 108 -4634 13528 27239 64451 46905 83803 815
I'm trying below code to plot graph but its not giving expected output
def draw_method():
while True:
plt.cla()
temp_var = live_data()
final_dataframe = pd.DataFrame(temp_var)
final_dataframe.set_index('TIME').plot(figsize = (10,5),grid=True)
plt.gcf()
plt.show()
sleep(30) #30 seconds sleep to add updated data field in dataframe
also, how can I give single color for all columns which has CE_ and single color to PE_ in graph? The graph I'm getting had different color for each line.
Thanks so much for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。告诉我情况如何。值得注意的是,我的变化如下。我非常怀疑您是否想每30秒显示一次以上的窗口,因此我从您那里拿出了plt.show()。而且我利用了Funcanimation,因为那个家伙将多次调用您的数据框架,并为您更新。非常有用。
Try this. And tell me how it went. Is worth noting, my changes were the following. I highly doubt you want to make more than one window be displayed every 30 seconds so i took out plt.show() from you func. And i utilized the FuncAnimation, cause that guy is going to call your dataframe multiple times, and update it for you. Very usefull.