我有一个带有导航工具栏的简单图表。当我缩放或平移时,图形会正确更新,但轴标签会混乱。就好像它在绘制新文本之前没有清除旧文本一样。因此,您会看到新文本覆盖了旧文本。如果我调整窗口大小,它似乎会重新绘制并修复标签。这是我的简单示例:
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
from Tix import *
from Tkconstants import *
root = Tk()
f = Figure(figsize=(12,5), dpi=100, frameon=False)
s = f.add_subplot(111, title="test")
x = [0,1,2,3,4,5]
y = [5,2,6,7,3,6]
s.plot(x,y,label="Test")
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
NavigationToolbar2TkAgg(canvas, root)
root.mainloop()
这是之前的:
这是平移之后: