修复多行更新颜色的颜色matplotlib
我有一个numpy数组:
- col [0] = time = xaxis_data
- col [1:32] = y轴的线。
每一秒,一个新的数据将添加到数组中。
我正在绘制数据并更新图,但是我无法获得每行的颜色以保持固定。
import numpy as np
import time
import matplotlib.pyplot as plt
#add time column
start_measurment = time.time()
#storing the updated data
to_plot = np.zeros((1, 33))
#maybe using this? my_colors = plt.rcParams['axes.prop_cycle'][:32]()
fig,ax = plt.subplots(1,1)
ax.set_xlabel('time(s)')
ax.set_ylabel('sim. Data')
for i in range (20): #updating plot 20 times
#simulate the data for Stack example
Simulated_data = (np.arange(32)*i).reshape((1, 32))
#insert the time as col[0]
Simulated_data = np.insert(Simulated_data, 0, [time.time()-start_measurment], axis=1) #insert time
#append new data to a numpy array
to_plot = np.append(to_plot,Simulated_data , axis=0)
#Plot Data
ax.plot(to_plot[:,0], to_plot[:,1:]) #Add here how to fix colours
fig.canvas.draw()
time.sleep(1)
I have a numpy array with:
- col[0]=time=xaxis_data
- col[1:32]= lines for y axis.
Every second a new row of data is added to the array.
I am plotting the data and updating the plots, however I cannot get the colors of each line to stay fixed.
import numpy as np
import time
import matplotlib.pyplot as plt
#add time column
start_measurment = time.time()
#storing the updated data
to_plot = np.zeros((1, 33))
#maybe using this? my_colors = plt.rcParams['axes.prop_cycle'][:32]()
fig,ax = plt.subplots(1,1)
ax.set_xlabel('time(s)')
ax.set_ylabel('sim. Data')
for i in range (20): #updating plot 20 times
#simulate the data for Stack example
Simulated_data = (np.arange(32)*i).reshape((1, 32))
#insert the time as col[0]
Simulated_data = np.insert(Simulated_data, 0, [time.time()-start_measurment], axis=1) #insert time
#append new data to a numpy array
to_plot = np.append(to_plot,Simulated_data , axis=0)
#Plot Data
ax.plot(to_plot[:,0], to_plot[:,1:]) #Add here how to fix colours
fig.canvas.draw()
time.sleep(1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我认为您无法在单行绘图语句中绘制不同的颜色,但是如果您将嵌套循环放入嵌套,则可能是可能的:
I don't think you can plot different colours in a single line plot statement but if you put in a nested for loop it is then possible: