Hi again, developers. I found that Axes.autoscale_view, and therefore Axes.autoscale, won't scale loosely when all of the children are images. Passing tight=False yields behavior just like tight=None. The attached script demonstrates this. In contrast, the docs for autoscale indicate that tight=False should force loose scaling. I believe the attached patch yields the desireable and documented behavior; would you please review it? Thank you.
For those who might need to work around the issue, the following can
accomplish a loose scaling:
axes.autoscale_view() # tight scaling to image extent
axes.set_xbound(
*axes.xaxis.get_major_locator().view_limits(
*axes.get_xbound()))
axes.set_ybound(
*axes.yaxis.get_major_locator().view_limits(
*axes.get_ybound()))
"""
Demonstrates that, as of v. 1.0.0, Axes.autoscale_view always uses tight
scaling when all children are images, regardless of the passed *tight*
parameter. Effectively, tight=False acts like tight=None.
"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
field = np.array([[0, 1], [1, 0]]) # image data
extent = l, r, b, t = (-1.5, 1.5, -1.5, 1.5) # Extents will lie between ticks.
tight_seq = (None, False, True) # values of *tight* to test
# Make two rows and a column of subplots for each *tight* value.
fig, axes = plt.subplots(2, len(tight_seq))
for ax in axes.flat: # In all subplots,
ax.imshow(field, extent=extent) # show the image
ax.xaxis.set_major_locator(mtick.MultipleLocator(1)) # and set locators.
ax.yaxis.set_major_locator(mtick.MultipleLocator(1))
for ax in axes[1]: # In the second row,
ax.plot([l, r], [b, t], 'g-') # plot a line across the image.
for ax_row in axes:
for (ax, tight) in zip(ax_row, tight_seq): # Apply each *tight* value
ax.autoscale_view(tight=tight) # to the subplot...
if ax.is_first_row():
ax.set_title('tight = %s' % tight) # and title.
plt.show()
axes.Axes.autoscale_view.patch
Description: Binary data
------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb
_______________________________________________ Matplotlib-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
