简体   繁体   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

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 时,我得到这样的图表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.

相关问题 如何使用 matplotlib 绘制具有大方差的值 - how can I plot values with big variance using matplotlib 我如何告诉python我的数据结构(二进制)是什么样子,以便我可以绘制它? - How do I tell python what my data structure (that is in binary) looks like so I can plot it? 如何使用matplotlib为我的图形制作动画,以便看起来数据点在移动? - How can I animate my graph with matplotlib so that it looks like the data points are moving? 我想使用 matplotlib 从 dataframe 中 plot 多个变量,但最终的 Z32FA6E1B78A9D422AACZE 看起来很奇怪 - I want to plot multiple variables from a dataframe using matplotlib but the final plot looks so weird Matplotlib:如何使用数组中存储的值进行绘图? - Matplotlib: How to plot using values stored in an array? 如何在matplotlib中使用imshow将NaN值绘制为特殊颜色? - How can I plot NaN values as a special color with imshow in matplotlib? 如何在matplotlib中正确绘制-dBc值? - How can I properly plot -dBc values in matplotlib? 我如何使用seaborn或matplotlib在python中绘制分类特征与分类值 - How can I plot a categorical feature vs categorical values in python using seaborn or matplotlib 如何在 Python 中使用 matplotlib 在绘图中的所有 x 值的 xaxis 中以小时和分钟格式显示标签? - How can I show labels in hours and minutes format in xaxis for all x values in a plot using matplotlib in Python? 如何在 R 中创建一个看起来像附件图像的图? - How can I create a plot in R that looks like the attached image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM