我使用 matplotlib 通过复制背景和位块传输来制作绘图动画:
f = Figure(tight_layout=True)
canvas = FigureCanvasTkAgg(f, master=pframe)
canvas.get_tk_widget().pack()
ax = f.add_subplot(111)
# Set inial plot title
title = ax.set_title("First title")
canvas.show()
# Capture the background of the figure
background = canvas.copy_from_bbox(ax.bbox)
line, = ax.plot(x, y)
canvas._tkcanvas.pack()
我定期更新情节:
# How to update the title here?
line.set_ydata(new_data)
ax.draw_artist(line)
canvas.blit(ax.bbox)
每次更新绘图时,如何尽可能有效地更新绘图标题?
Edit:
title.set_text("New title")
ax.draw_artist(title)
之前或之后
canvas.blit(ax.bbox)
不更新标题。我想我应该以某种方式重新绘制title
艺术家,或者我应该只捕获图表,因为blit(ax.bbox)
覆盖整个标题绘图区域,包括标题。
几年后突然说,过去几天我也被这个问题困扰,禁用 blit 对我来说不是一个选择(因为 fps 会变得太慢)。至少对于 matplotlib 3.1.3,如果您向画布发送调整大小事件,它会正确刷新背景并通过任何更新重新生成它。因此,您可以通过检测何时需要更新标题来解决此问题,然后调用fig.canvas.resize_event()
强制冲洗。希望这对未来的人有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)