我使用matplotlib动画情节,通过复制背景和位图传送:带blit的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)
我怎么可以更新 - 尽可能高效,情节每次更新剧情时都会有标题?
编辑:
title.set_text("New title")
ax.draw_artist(title)
之前或之后
canvas.blit(ax.bbox)
不更新的称号。我认为我应该重绘title
艺术家,或者我应该只捕捉图表,因为blit(ax.bbox)
会覆盖整个标题情节区域,包括标题。
你可以用'title.set_text(“第二个标题”) '更新标题。 –
@Ed Smith不幸的是'title.set_text(“Second title”)'不会更新标题,可能标题文本艺术家应该重绘? –
嗨@Eugen Epure,你确实需要重绘,我已经用最小的例子添加了一个答案来显示 –