把下面这段代码改成同时动态显示图aa=api.get_tick_serial(“SHFE.hc2310”,8000).last_price.values diff = [j-i for i, j in zip(aa[:-1], aa[6:])] a = [] b=[] # fig, ax = plt.subplots() for i in aa: plt.subplot(211) plt.clear() plt.plot(a) plt.pause(0.5) a.append(i) # 在a的末尾添加一个新元素,模拟a的动态变化 # plt.show() for j in diff: plt.subplot(212) plt.clear() plt.plot(b) plt.pause(0.5) b.append(j) plt.show()
时间: 2023-12-31 13:04:39 浏览: 118
图形的动态显示
以下是修改后的代码,可以同时动态显示图:
```
import matplotlib.pyplot as plt
aa = api.get_tick_serial("SHFE.hc2310", 8000).last_price.values
diff = [j-i for i, j in zip(aa[:-1], aa[6:])]
a = []
b = []
fig, (ax1, ax2) = plt.subplots(2, 1)
for i in aa:
ax1.clear()
a.append(i)
ax1.plot(a)
plt.pause(0.5)
for j in diff:
ax2.clear()
b.append(j)
ax2.plot(b)
plt.pause(0.5)
plt.show()
```
阅读全文