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
The code to get this graph from matplotlib import pyplot as plt plt.plot(new3[:100]) plt.show()
What should I do to plot this graph in say 25 seconds. I mean there should be a live plotting for a similar graph and it should be completed in 25 seconds. 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:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.