我目前正在 Python 中使用 matplotlib 使用 for 循环将数据绘制到图形中。该循环循环遍历数据集并每次获取新的“x”和“y”,然后使用plt.plot(x,y)
绘制 x 和 y 数据,然后将绘图添加到当前图形;我最终得到了多个图,这些图全部放置在一个图中。
Ex)
x_data_arr = [[11,5,4], [2,5,1], ...] #list of lists containing x data points
y_data_arr = [[2,7,3], [9,2,6], ...] #list of lists containing y data points
plt.figure(num='fig1') #establish figure to plot to
for q in range(0, 100):
x = x_data_arr[q] #get x data (list of x data points)
y = y_data_arr[q] #get y data (list of x data points)
plt.plot(x,y) #plot this x and y to fig1 and restart loop to get/plot next x and y dataset
plt.show() #shows all plots over one another on a single figure
我希望提高连续通话的性能plt.plot()
, as plt.plot()
当前正在阻止 for 循环继续,直到绘图完成,当有很多绘图需要循环时,这是非常及时的,并且如果所有plt.plot()
可以同时进行
这样,有没有一种方法可以使用多线程或多处理来执行每个plt.plot()
在不同的线程或处理器上?我不太熟悉多处理的语法,我相信在 matplotlib 不是线程安全的情况下,这可能是更好的选择(但这可能并不重要,因为每个图都是不同的)
任何帮助,将不胜感激!