外形尺寸Matplotlib缩放后的位置

编程入门 行业动态 更新时间:2024-10-26 08:33:21
本文介绍了外形尺寸Matplotlib缩放后的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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缩放后的位置

本文发布于:2023-10-08 08:56:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   外形尺寸   位置   Matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!