【问题标题】:Reset Toolbar History in Matplotlib with Qt4Agg backend使用 Qt4Agg 后端在 Matplotlib 中重置工具栏历史记录
【发布时间】:2017-11-10 08:26:45
【问题描述】:

我有一个单独的绘图线程,带有 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()

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

P.s.:“主页”-按钮 = 重置原始视图

【问题讨论】:

    标签: python matplotlib qt4 toolbar


    【解决方案1】:

    我终于能够通过反复试验弄明白了。有更新工具栏的功能。这将更新工具栏的历史并将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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 2021-10-02
      • 2020-10-17
      相关资源
      最近更新 更多