使用 Qt4Agg 后端在 Matplotlib 中重置工具栏历史记录
Reset Toolbar History in Matplotlib with Qt4Agg backend
我有一个单独的绘图线程,其中包含 matplotlib 和多进程。现在,如果我以交互方式放大 window,autoscale_view() 将不再起作用(使用 autoscale() 修复)。但是工具箱中的 "home" 按钮仍然不起作用:它似乎调用 autoscale_view() 并且不显示更新的视图但显示旧视图(在放大时)。示例代码:
import matplotlib
matplotlib.use("qt4agg")
from matplotlib import pyplot as plt
import multiprocessing
def reset_view():
plt.get
xdata = []
ydata = []
temp = 0
test_ax = plt.gca()
test_line, = plt.plot(xdata, ydata)
plt.show(block=False)
for i in range(10):
temp = temp+1
xdata.append(temp)
ydata.append(temp)
test_line.set_data(xdata, ydata)
test_ax.relim()
test_ax.autoscale(tight= False)
plt.show(block=False)
plt.pause(2)
plot_thread = multiprocessing.Process(target = reset_view, args = ())
reset_view()
if __name__ == '__main__':
plot_thread.start()
尝试在绘图期间放大并在之后按主页按钮。有没有办法让主页按钮使用 autoscale() 而不是 autoscale_view() 或重置和更新工具栏历史记录,以便它不会跳回旧视图?
P.s.: "Home"-按钮=重置原始视图
我终于通过反复试验弄明白了。有更新工具栏的功能。这会更新工具栏的历史记录并将 home()
函数设置为新视图。解决方案:
figure = plt.gcf() #Get current figure
toolbar = figure.canvas.toolbar #Get the toolbar handler
toolbar.update() #Update the toolbar memory
plt.show(block = False) #Show changes
我有一个单独的绘图线程,其中包含 matplotlib 和多进程。现在,如果我以交互方式放大 window,autoscale_view() 将不再起作用(使用 autoscale() 修复)。但是工具箱中的 "home" 按钮仍然不起作用:它似乎调用 autoscale_view() 并且不显示更新的视图但显示旧视图(在放大时)。示例代码:
import matplotlib
matplotlib.use("qt4agg")
from matplotlib import pyplot as plt
import multiprocessing
def reset_view():
plt.get
xdata = []
ydata = []
temp = 0
test_ax = plt.gca()
test_line, = plt.plot(xdata, ydata)
plt.show(block=False)
for i in range(10):
temp = temp+1
xdata.append(temp)
ydata.append(temp)
test_line.set_data(xdata, ydata)
test_ax.relim()
test_ax.autoscale(tight= False)
plt.show(block=False)
plt.pause(2)
plot_thread = multiprocessing.Process(target = reset_view, args = ())
reset_view()
if __name__ == '__main__':
plot_thread.start()
尝试在绘图期间放大并在之后按主页按钮。有没有办法让主页按钮使用 autoscale() 而不是 autoscale_view() 或重置和更新工具栏历史记录,以便它不会跳回旧视图?
P.s.: "Home"-按钮=重置原始视图
我终于通过反复试验弄明白了。有更新工具栏的功能。这会更新工具栏的历史记录并将 home()
函数设置为新视图。解决方案:
figure = plt.gcf() #Get current figure
toolbar = figure.canvas.toolbar #Get the toolbar handler
toolbar.update() #Update the toolbar memory
plt.show(block = False) #Show changes