覆盖 matplotlib 的平移工具 (wx) [英] overriding matplotlib's panning tool (wx)

查看:36
本文介绍了覆盖 matplotlib 的平移工具 (wx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用安装在 wxPython 面板中的 matplotlib 来进行一些繁重的绘图.我的问题出现在使用本机平移工具时 - 看起来好像 matplotlib 在您拖动平移手柄时试图不断重绘画布.随着我绘制的数据量变得非常不稳定(已经使用数据集等进行了优化)

I'm using matplotlib housed in a wxPython panel to do some heavy duty plotting. My issues comes when using native panning tool - it's appears as though matplotlib tries to constantly redraw the canvas as you drag the pan handle around. With the amount of data I'm plotting this is getting really choppy (already optimized with Collections for data etc)

就性能而言,我认为画布在平移结束时释放鼠标时只绘制一次会更可取.我意识到这意味着我必须用我自己的类来扩展 WxAgg NavigationToolbar2 类,但我想知道是否有人尝试过类似的方法并且可以建议我覆盖哪些函数?

In terms of performance I think it would be much preferable for the canvas to just draw once when the mouse is released at the end of a pan. I realise this will mean I have to extend the WxAgg NavigationToolbar2 class with my own, but I'm wondering if anyone has attempted something similar to this and can advise me on which functions to override?

非常感谢

推荐答案

我花了很多时间对 matplotlib 后端进行修改,我从来没有做过这个具体的修改,但我可以给你看一行代码注释掉将停止动态更新:

I've spent a lot of time making modification on the matplotlib backends, I've never done this specific change, but I can show you one line of code to comment out that will stop the dynamic updating:

我假设您正在使用 WxAgg 后端,如果是这种情况,请打开此文件:C:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py

I presume you are using the WxAgg backend, if this is the case, open this file: C:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py

并注释掉此处指示的行:

And comment out the line indicated here:

def dynamic_update(self):
    d = self._idle
    self._idle = False
    if d:
        #self.canvas.draw() #<--- Comment out to stop the redrawing during the Pan/Zoom
        self._idle = True

我对此进行了测试,它似乎很好地解决了您的问题.我进行了一些快速挖掘,但没有看到任何其他函数调用此过程,因此您甚至可以将其更改为:

I tested this and it seems to nicely solve your issue. I did some quick digging and I didn't see any other functions calling this procedure so you might even be able to just change it to:

def dynamic_update(self):
    pass

...与您在基本 NavigationToolbar2

...Which is the same code you'll find in the base NavigationToolbar2 class

(当然,如果你对这个改变感到满意,你可以做更多的工作,通过这种修改来制作你自己的自定义后端.只是为了确保你在升级 matplotlib 时不会丢失更改)

(And of course, if you're happy with this change you can do a little more work to make your own custom backend with this kind of modification. Just to make sure you don't lose the change when upgrading matplotlib)

这篇关于覆盖 matplotlib 的平移工具 (wx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆