3

我在 wxPython 面板中有一个 matplotlib 图像图,我使用本机 matplotlib 工具栏缩放进行放大。

放大后,我想知道生成图像的大小,以便计算放大倍数。

此外,我想知道我的放大图像相对于原始图像的位置/尺寸,以便我以后可以重新绘制它。

我不知道如何处理这个问题。我查看了文档canvasfigure但没有找到任何可以帮助我确定所需数据的内容。谢谢你的帮助。

4

1 回答 1

3

You may want to read the following from the matplotlib doc:

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.

于 2014-08-19T08:08:47.303 回答