【发布时间】:2018-06-30 23:39:40
【问题描述】:
jsontime = [-9,-8,-7,-6,-5,-4,-3,-2,-1,0]
f, axarr = plt.subplots(1, 1)
ax1 = axarr[0, 0]
ax2 = axarr[0, 1]
def tempa_plot():
jsontempa = []
ay=[]
for k in range(100):
jsontempaval = random.randint(30, 80)
jsontempa.append(jsontempaval)
print(len(jsontempa))
for i in jsontempa:
ay.append(i)
if len(ay) > 10:
ay.pop(0)
ax1.ylim(30, 80) # Set y min and max values
ax1.xlim(-9, 1)
ax1.title('Live Streaming Sensor Data: Temperature')
ax1.grid(True)
ax1.ylabel('Temp C') # Set ylabels
ax1.xlabel('Time')
ax1.plot(jsontime,ay,label='Degrees C')
ax1.legend(loc='upper left') # plot the legend
ax1.pause(0.2)
ax1.clf()
ax1.set_title('Axis [0,0]')
def tempb_plot():
jsontempb = []
by=[]
for k in range(100):
jsontempaval = random.randint(50, 100)
jsontempb.append(jsontempaval)
print(len(jsontempb))
for i in jsontempb:
by.append(i)
if len(by) > 10:
by.pop(0)
print(by)
ax2.ylim(45, 105) # Set y min and max values
ax2.xlim(-9, 1)
ax2.title('Live Streaming Sensor Data: Temperature b')
ax2.grid(True)
ax2.ylabel('Temp C') # Set ylabels
ax2.xlabel('Time')
ax2.plot(jsontime,by,label='Degrees C')
ax2.legend(loc='upper left') # plot the legend
ax2.pause(0.2)
ax2.clf()
axarr[0, 1].set_title('Axis [0,0]')
tempa_plot()
tempb_plot()
这会引发轴不可下标的错误。 我有来自我的 Arduino 的源源不断的数据流。我应该尝试多线程吗?有没有更简单、更有效的方法来做到这一点?我尝试从不同的程序运行,效果很好。 TIA
【问题讨论】:
标签: python matplotlib live-streaming