我在Python中使用Matplotlib进行“实时”绘图代码,但一旦完成就会关闭。我希望情节保持开放。
以下代码
bootstrapToggle.d.ts
答案 0 :(得分:1)
也许你想要像this这样的东西:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def make_data():
for i in range(100):
yield i, i*2
fig, ax = plt.subplots()
color = plt.cm.cubehelix(np.linspace(0.1,0.9,100))
plot, = ax.plot([], [],'o')
xdata, ydata = [], []
ax.set_ylim(0, 1)
ax.set_xlim(0, 1)
def run(data):
x,y = data
xdata.append(x)
ydata.append(y)
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
if y > ymax:
ax.set_xlim(xmin, 1+xmax)
ax.set_ylim(ymin, 1+ymax)
ax.figure.canvas.draw()
plot.set_color(color[x])
plot.set_data(xdata,ydata)
return plot,
ani = animation.FuncAnimation(fig,run,make_data,blit=True,interval=10,repeat=False)
plt.show()
也许散射会更好,因为它可能允许每个圆圈的不同颜色。