繁体   English   中英

我有一个值数组,如何使用 matplotlib 的 plot 值使其看起来像 25 秒的视频

[英]I have an array of values, how can I plot values using matplotlib so that it looks like a video of 25 seconds

我有一组值

2515, 2513, 2513, 2513, 2513, 2512, 2515, 2511, 2526, 2513, 2511, 2500, 2521, 2511, 2523, 2512, 2529, 2513, 2526, 2514, 2518, 2512, 2524, 2512, 2527, 2512, 2521, 2512, 2517, 2514, 2522, 2512, 2521, 2512, 2528, 2511, 2523, 2512, 2518, 2513, 2522, 2512, 2511, 2512, 2524, 2512, 2515, 2512, 2509, 2512, 2515, 2512, 2528, 2512, 2516, 2512, 2527, 2512, 2526, 2512, 2528, 2512, 2529, 2512, 2523, 2511, 2526, 2512, 2521, 2513, 2510, 2512, 2523, 2513, 2500, 2511, 2518, 2512, 2513, 2512, 2526, 2512, 2526, 2512, 2520, 2512, 2526, 2512, 2519, 2500, 2529, 2511, 2514, 2512, 2522, 2512, 2513, 2512, 2515, 2512]

当我使用 matplotlib 时,我得到这样的图表Matplotlib 图

from matplotlib import pyplot as plt plt.plot(new3[:100]) plt.show()

我应该在 25 秒内对 plot 这个图表做什么。 我的意思是应该有一个类似图表的实时绘图,它应该在 25 秒内完成。 我不是在寻找多个图表 我希望所有更新都只在一个图表中进行

您可以使用 Numpy 的arange创建一个 25 秒的范围,频率为您想要的时间(25 秒)除以点的总数(数据的长度),如下所示:

import matplotlib.pyplot as plt
import numpy as np

data = [2515, 2513, 2513, 2513, 2513, 2512, 2515, 2511, 2526, 2513, 2511, 2500, 2521, 2511, 2523, 
        2512, 2529, 2513, 2526, 2514, 2518, 2512, 2524, 2512, 2527, 2512, 2521, 2512, 2517, 2514, 
        2522, 2512, 2521, 2512, 2528, 2511, 2523, 2512, 2518, 2513, 2522, 2512, 2511, 2512, 2524, 
        2512, 2515, 2512, 2509, 2512, 2515, 2512, 2528, 2512, 2516, 2512, 2527, 2512, 2526, 2512, 
        2528, 2512, 2529, 2512, 2523, 2511, 2526, 2512, 2521, 2513, 2510, 2512, 2523, 2513, 2500, 
        2511, 2518, 2512, 2513, 2512, 2526, 2512, 2526, 2512, 2520, 2512, 2526, 2512, 2519, 2500, 
        2529, 2511, 2514, 2512, 2522, 2512, 2513, 2512, 2515, 2512]

timePeriod = 25 # 25 seconds
x_axis = np.arange(0, timePeriod, timePeriod/len(data))

plt.plot(x_axis, data)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM