Figure Size & Position After Matplotlib Zoom
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
Solution 1:
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))
defondraw(event):
# print 'ondraw', event# these ax.limits can be stored and reused as-is for set_xlim/set_ylim laterprint 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.
Post a Comment for "Figure Size & Position After Matplotlib Zoom"