[英]I have an array of values, how can I plot values using matplotlib so that it looks like a video of 25 seconds
I have a array of values我有一组值
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]
When I am using matplotlib I am getting a graph like this当我使用 matplotlib 时,我得到这样的图表
The code to get this graph from matplotlib import pyplot as plt plt.plot(new3[:100]) plt.show()
from matplotlib import pyplot as plt plt.plot(new3[:100]) plt.show()
What should I do to plot this graph in say 25 seconds.我应该在 25 秒内对 plot 这个图表做什么。 I mean there should be a live plotting for a similar graph and it should be completed in 25 seconds.我的意思是应该有一个类似图表的实时绘图,它应该在 25 秒内完成。 I am not looking for multiple graph I want all the updates to be made in a single graph only我不是在寻找多个图表 我希望所有更新都只在一个图表中进行
You can use Numpy's arange
to create a range of 25 seconds with the frequency being the time you want (25 seconds) divided by the total number of points (the length of your data) like so:您可以使用 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.