如何重置NavigatonToolbar“history”当重新绘制同一轴上的数据? [英] How to reset NavigatonToolbar "history" when re-plotting data on the same axis?

查看:122
本文介绍了如何重置NavigatonToolbar“history”当重新绘制同一轴上的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用matplotlib重复绘制数据的wxPython应用程序。
代码如下所示:

  import matplotlib 
matplotlib.use('WXAgg')$从matplotlib.figure中导入图b $ b从matplotlib.backends.backend_wxagg中导入图
导入FigureCanvasWxAgg作为FigCanvas,\
NavigationToolbar2WxAgg作为NavigationToolbar

self.fig =图((4, 5),dpi = 100,facecolor =white)
self.canvas = FigCanvas(self.panel,-1,self.fig)
self.toolbar = NavigationToolbar(self.canvas)
self.axes = self.fig.add_subplot(111)

每次我想绘制一些东西时,我只是设置x和y,然后执行:

  self.axes.plot(x,y,color = self.colours [i ],label = text)
self.canvas.draw()

正如你所看到的,我有一个NavigationToolBar绑定到画布。当我想绘制一个新图时,我打电话给:

  self.axes.clear()
self.axes .plot(x,y,color = self.colours [i],label = text)
self.canvas.draw()

问题在于:如果我在显示图形时使用工具栏的工具(缩放,平移,等等),工具栏的历史将不会重置我稍后绘制一张新图。如果我尝试在这个新图形中使用工具栏,工具栏将使用的视图(当我点击home或任何step时)将是旧图的视图。



我对matplotlib有点新,而且我可能做错了什么。
任何人都可以帮我解决这个问题吗?
在此先感谢,对于任何语法错误感到抱歉,
英语不是我的母语。

>您可以尝试:

  self.toolbar._views.clear()
self.toolbar._positions.clear( )
self.toolbar._update_view()#也许你不需要这个

我应该强调这是没有文件记录的,而且你正在接触和嘲笑图书馆的内部,所以不能保证,如果它现在有效,它将在未来工作(否则你会发出警告,说它将停止工作) 。 $ b

查看 matplotlib / backend_bases.py 中的代码,了解 NavigationToolbar2 (Wx版本的父类)有效。


I have a wxPython application that uses matplotlib for plotting data repeatedly. The code looks something like this:

import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas, \
NavigationToolbar2WxAgg as NavigationToolbar

self.fig = Figure((4,5), dpi = 100, facecolor = "white")
self.canvas = FigCanvas(self.panel, -1, self.fig)
self.toolbar = NavigationToolbar(self.canvas)
self.axes = self.fig.add_subplot(111)

Everytime I want to plot something, I just set x and y and do:

self.axes.plot(x,y, color = self.colours[i], label = text)
self.canvas.draw()

As you can see, I have a NavigationToolBar bound to the canvas. When I want to plot a new graph, I call:

self.axes.clear()
self.axes.plot(x,y, color = self.colours[i], label = text)
self.canvas.draw()

Here comes the problem: If I use the toolbar's tools (zoom, steps, pan, etc) when I'm visualizing a plot, the "historic" of the toolbar won't reset when I plot a new graph later. If I try to use the toolbar in this new graph, the views the toolbar will use (when I click "home" or any "step") will be the views of the old plot.

I'm kinda new to matplotlib and I'm probably doing something wrong. Can anyone help me out with this? Thanks in advance, and sorry for any grammar mistakes, English is not my mother language.

解决方案

You might try:

self.toolbar._views.clear()
self.toolbar._positions.clear()
self.toolbar._update_view() # maybe you don't need this

I should stress this is un-documented and you are reaching in and poking at the innards of the library, so there is no guarantee that if it works now, it will work in the future (or you will get warning that it will stop working).

Have a look at the code in matplotlib/backend_bases.py for how the NavigationToolbar2 (the parent class of the Wx version) works.

这篇关于如何重置NavigatonToolbar“history”当重新绘制同一轴上的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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