我在wxPython面板中有一个matplotlib图像绘图,我使用本地的matplotlib工具栏缩放进行了放大。放大后,我希望知道结果图像的大小,以便计算放大倍率。此外,我还想知道缩放后的图像相对于原始图像的位置/尺寸,以便稍后重新绘制。我不知道该如何处理这个问题。我查看了canvas和figure的文档,但没有找到任何可以帮助我确定所需数据的内容。感谢任何帮助。
您可能需要阅读matplotlib文档中的以下内容:
然而,特别是变换教程可能需要一些时间才能理解。变换系统非常高效和完整,但是可能需要一段时间才能确定您确实需要什么。
然而,在您的情况下,以下代码片段可能已经足够:
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()