带有Matplotlib的Python和交互式缩放图 [英] Python and Interactive Zoom Plot with Matplotlib

查看:654
本文介绍了带有Matplotlib的Python和交互式缩放图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在wxPython窗格内使用Matplotlib图(带有底图).我得到了情节(美国地图与城市的散点图).我正在尝试进行一些交互式缩放功能(在地图上选择一个框,然后仅缩放"到该区域).

I am using a Matplotlib plot (with Basemap) inside of a wxPython pane. I have got the plot (US map with scatter plot of cities). I am trying to do some interactive zoom capabilities (select a box on the map and "zoom" into that area only).

我设法显示了工具栏,但是当我单击按钮时,什么也没有发生.好像工具栏就在那里显示.有什么想法吗?这是我的代码:

I have managed to get the toolbar to show, but when i click on the buttons, nothing happens. Seems like the toolbar is just there for show. Any Thoughts? Here is my code:

        # Set up area for plotting Basemap Plot and scatter plot
        self.figure = Figure(None,dpi=75)
        self.canvas = FigureCanvas(self.PlotPanel, -1, self.figure)
        self.axes = self.figure.add_axes([0,0,1,1],frameon=False)
        self.SetColor( (255,255,255) )

        # Toolbar Set up
        self.toolbar=NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()
        tw,th = self.toolbar.GetSizeTuple()
        fw,fh = self.canvas.GetSizeTuple()
        self.toolbar.SetSize(wx.Size(fw,th))
        sizer_7.Add(self.toolbar,0)
        self.toolbar.update()

推荐答案

看看 embedding_in_wx2 示例,对我来说很好.

Have a look at the embedding_in_wx2 example, which works fine for me.

也许您的导入有问题:首先必须导入matplotlib,然后设置后端(matplotlib.use('WXagg')),然后导入后端.

Maybe there is something wrong with your imports: you first have to import matplotlib, than set the backend (matplotlib.use('WXagg')) and then import the backend.

但是,要在没有所有进口商品的完整示例的情况下帮助您并非易事.

However it isn't easy to help you without having a full example with all imports.

这篇关于带有Matplotlib的Python和交互式缩放图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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