plt实时动态绘图
plt动态绘图APIplt.ion():开启交互模式plt.ioff():关闭交互模式plt.clf():清理残留图像plt.pause():暂停例子import matplotlib.pyplot as pltplt.ion()x = []y = []for i in range(100):x.append(i)y.append(i ** 2)...
·
plt动态绘图
API
plt.ion()
:开启交互模式plt.ioff()
:关闭交互模式plt.clf()
:清理残留图像plt.pause()
:暂停
例子
import matplotlib.pyplot as plt
plt.ion()
x = []
y = []
for i in range(100):
x.append(i)
y.append(i ** 2)
plt.clf()
plt.plot(x, y)
plt.pause(0.1)
plt.ioff()
范围限制
import matplotlib.pyplot as plt
def draw_func(draw_count=None):
data = []
plt.ion()
def __draw(_data, keep=False):
data.append(_data)
length = len(data)
start = 0
if (draw_count is not None) and isinstance(draw_count, int) and (draw_count < length):
draw_data = data[-draw_count:]
start = length - draw_count
else:
draw_data = data
idx = [x for x in range(start, length)]
plt.clf()
plt.plot(idx, draw_data)
plt.pause(0.1)
if keep:
plt.show()
else:
plt.ioff()
return __draw
if __name__ == '__main__':
draw = draw_func(30)
for i in range(100):
draw(i ** 2, i == 99)
更多推荐
已为社区贡献3条内容
所有评论(0)