使用 Qt4Agg 后端在 Matplotlib 中重置工具栏历史记录

Jam*_*üeb 1 python qt4 matplotlib toolbar

我有一个带有 matplotlib 和多进程的单独绘图线程。现在,如果我以交互方式放大窗口,则 autoscale_view() 不再起作用(使用 autoscale() 修复)。但是工具箱中的“主页”按钮仍然不起作用:它似乎调用了 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()
Run Code Online (Sandbox Code Playgroud)

尝试在绘图期间放大,然后按主页按钮。有没有办法让主页按钮使用 autoscale() 而不是 autoscale_view() 或重置并更新工具栏历史记录,以便它不会跳回旧视图?

Ps:“主页”-按钮=重置原始视图

Jam*_*üeb 6

我终于能够通过反复试验弄清楚了。有更新工具栏的功能。这将更新工具栏的历史记录并将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
Run Code Online (Sandbox Code Playgroud)