我在wxPython面板中有一个matplotlib图像图,可以使用本机matplotlib工具栏缩放来放大.
I have a matplotlib image plot within a wxPython panel that I zoom in on using the native matplotlib toolbar zoom.
放大后,我希望知道生成图像的大小,以便可以计算放大倍数.
Having zoomed in I wish to know the size of the resulting image so that I can calculate the magnification.
此外,我想知道放大图像相对于原始图像的位置/尺寸,以便以后可以重新绘图.
Moreover, I wish to know the position/dimensions of my zoomed in image in relation to the original image so that I can re-plot it again at a later time.
我不知道该如何处理.我查看了canvas和figure的文档,但是没有找到任何可以帮助我确定所需数据的内容.谢谢你的帮助.
I don't know how to approach this. I have looked over documentation for canvas and figure but haven't found anything which would help me pin point the data I require. Thanks for any help.
推荐答案您可能想从matplotlib文档中阅读以下内容:
You may want to read the following from the matplotlib doc:
- 事件处理和选择
- 转换教程
- Event handling and picking
- Transformations tutorial
但是,尤其是转换教程可能需要花费一些时间来解决.转换系统非常有效且完整,但是您可能要花一些时间才能弄清您确实需要什么.
However, especially the transformations tutorial may take a while to wrap your head around. The transformation system is very efficient and complete, but it may take you a while to figure out what especially it is you do need.
但是,在您的情况下,以下代码片段可能就足够了:
However in your case maybe the following code snippet could be sufficient:
from matplotlib import pyplot as plt import numpy fig = plt.figure() ax = fig.add_subplot(111) ax.plot(numpy.random.rand(10)) def ondraw(event): # print 'ondraw', event # these ax.limits can be stored and reused as-is for set_xlim/set_ylim later print ax.get_xlim(), ax.get_ylim() cid = fig.canvas.mpl_connect('draw_event', ondraw) plt.show()在绘制事件中,您可以获取轴限制,计算缩放比例等,以后可以按原样使用以将轴设置为所需的缩放级别.
In the draw event you can get your axes limits, calculate a scaling and whatnot and can use it as-is later on to set the ax to the desired zoom level.
更多推荐
外形尺寸Matplotlib缩放后的位置
发布评论