使用Python的多个列的实时数据框架的图动态图

发布于 2025-02-13 16:39:26 字数 955 浏览 2 评论 0原文

我正在尝试使用实时数据绘制动态图。 以下是示例数据框,其中每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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2025-02-20 16:39:26

尝试一下。告诉我情况如何。值得注意的是,我的变化如下。我非常怀疑您是否想每30秒显示一次以上的窗口,因此我从您那里拿出了plt.show()。而且我利用了Funcanimation,因为那个家伙将多次调用您的数据框架,并为您更新。非常有用。

from matplotlib.animation import FuncAnimation


def draw_method():           
    plt.cla()
    temp_var = live_data()
    final_dataframe = pd.DataFrame(temp_var)
    final_dataframe.set_index('TIME').plot(figsize = (10,5),grid=True)

ani = FuncAnimation(plt.gcf(), draw_method, interval=1000)

plt.tight_layout()
plt.show()

temp_var = live_data()
final_dataframe = pd.DataFrame(temp_var)

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.

from matplotlib.animation import FuncAnimation


def draw_method():           
    plt.cla()
    temp_var = live_data()
    final_dataframe = pd.DataFrame(temp_var)
    final_dataframe.set_index('TIME').plot(figsize = (10,5),grid=True)

ani = FuncAnimation(plt.gcf(), draw_method, interval=1000)

plt.tight_layout()
plt.show()

temp_var = live_data()
final_dataframe = pd.DataFrame(temp_var)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文