Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

inverting an axis shouldn't affect the autoscaling setting #1557

Merged
merged 4 commits into from

6 participants

@WeatherGod
Collaborator

invert_xaxis() and friends shouldn't blindly set the axis limits. The autoscaling state should be left unchanged. There may be other places in the codebase where this change should be made.

Closes #1553

@pelson
Collaborator

Looks good to me.

Is this easy to test? If so, would you mind adding a simple test for this?

Cheers,

@WeatherGod
Collaborator

Yes, I was just about to push up a commit that tests this, but then I ran into the build failure on my machine.

@dmcdougall
Collaborator

@WeatherGod "The" build failure? The ones we've been seeing recently on Travis? The travis builds are succeeding now...

@WeatherGod
Collaborator
@dmcdougall
Collaborator

Whew ok. That's a relief.

@mdboom
Owner

As for "other places in the code that may need this update": I just did a quick grep. hist2d and spy both set the limits unconditionally like this -- I wonder what the implications of adding those are.

@WeatherGod
Collaborator

Ok, looks like I accidentally picked up a couple of the cherry-picked commits in my last rebase. Hopefully that isn't too much of an issue.

I will look into spy and hist2d.

@WeatherGod
Collaborator

wrt spy() and hist2d(), I have to question why they even need to explicitly set the limits. Maybe at the time, the autoscaling logic wasn't very good, but it is much more mature now. Perhaps we should update these to use autoscale_view()?

@efiring
Owner
@WeatherGod
Collaborator

We can certainly still do the same setting of the limits. I just suggest that the autoscaling state should be left alone.

@dmcdougall
Collaborator

@WeatherGod Is this good to go or are you going to add hist2d and spy to this PR?

@WeatherGod
Collaborator

I think I will leave spy and hist2d out. We will have to ponder it some more.

@dmcdougall
Collaborator

@WeatherGod Ok. Are you needing to add anything or can I merge this?

@WeatherGod
Collaborator

no, go ahead and merge.

@dmcdougall dmcdougall merged commit 07fa831 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 examples/api/custom_projection_example.py
@@ -262,25 +262,25 @@ def set_xlim(self, *args, **kwargs):
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
set_ylim = set_xlim
- def format_coord(self, long, lat):
+ def format_coord(self, lon, lat):
"""
Override this method to change how the values are displayed in
the status bar.
In this case, we want them to be displayed in degrees N/S/E/W.
"""
- long = long * (180.0 / np.pi)
+ lon = lon * (180.0 / np.pi)
lat = lat * (180.0 / np.pi)
if lat >= 0.0:
ns = 'N'
else:
ns = 'S'
- if long >= 0.0:
+ if lon >= 0.0:
ew = 'E'
else:
ew = 'W'
# \u00b0 : degree symbol
- return '%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(long), ew)
+ return '%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(lon), ew)
class DegreeFormatter(Formatter):
"""
View
4 lib/matplotlib/axes.py
@@ -2421,7 +2421,7 @@ def set_axis_bgcolor(self, color):
def invert_xaxis(self):
"Invert the x-axis."
left, right = self.get_xlim()
- self.set_xlim(right, left)
+ self.set_xlim(right, left, auto=None)
def xaxis_inverted(self):
"""Returns *True* if the x-axis is inverted."""
@@ -2641,7 +2641,7 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
def invert_yaxis(self):
"Invert the y-axis."
bottom, top = self.get_ylim()
- self.set_ylim(top, bottom)
+ self.set_ylim(top, bottom, auto=None)
def yaxis_inverted(self):
"""Returns *True* if the y-axis is inverted."""
View
12 lib/matplotlib/projections/geo.py
@@ -163,19 +163,19 @@ def set_xlim(self, *args, **kwargs):
set_ylim = set_xlim
- def format_coord(self, long, lat):
+ def format_coord(self, lon, lat):
'return a format string formatting the coordinate'
- long = long * (180.0 / np.pi)
+ lon = lon * (180.0 / np.pi)
lat = lat * (180.0 / np.pi)
if lat >= 0.0:
ns = 'N'
else:
ns = 'S'
- if long >= 0.0:
+ if lon >= 0.0:
ew = 'E'
else:
ew = 'W'
- return u'%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(long), ew)
+ return u'%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(lon), ew)
def set_longitude_grid(self, degrees):
"""
@@ -576,10 +576,10 @@ def transform_non_affine(self, xy):
lat = np.arcsin(cos_c*np.sin(clat) +
((y*sin_c*np.cos(clat)) / p))
- long = clong + np.arctan(
+ lon = clong + np.arctan(
(x*sin_c) / (p*np.cos(clat)*cos_c - y*np.sin(clat)*sin_c))
- return np.concatenate((long, lat), 1)
+ return np.concatenate((lon, lat), 1)
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
def inverted(self):
View
23 lib/matplotlib/tests/test_axes.py
@@ -419,6 +419,29 @@ def test_hexbin_extent():
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
+@cleanup
+def test_inverted_limits():
+ # Test gh:1553
+ # Calling invert_xaxis prior to plotting should not disable autoscaling
+ # while still maintaining the inverted direction
+ fig = plt.figure()
+ ax = fig.gca()
+ ax.invert_xaxis()
+ ax.plot([-5, -3, 2, 4], [1, 2, -3, 5])
+
+ assert ax.get_xlim() == (4, -5)
+ assert ax.get_ylim() == (-3, 5)
+ plt.close()
+
+ fig = plt.figure()
+ ax = fig.gca()
+ ax.invert_yaxis()
+ ax.plot([-5, -3, 2, 4], [1, 2, -3, 5])
+
+ assert ax.get_xlim() == (-5, 4)
+ assert ax.get_ylim() == (5, -3)
+ plt.close()
+
@image_comparison(baseline_images=['nonfinite_limits'])
def test_nonfinite_limits():
x = np.arange(0., np.e, 0.01)
View
2  lib/mpl_toolkits/mplot3d/axes3d.py
@@ -1389,7 +1389,7 @@ def invert_zaxis(self):
This function was added, but not tested. Please report any bugs.
"""
bottom, top = self.get_zlim()
- self.set_zlim(top, bottom)
+ self.set_zlim(top, bottom, auto=None)
def zaxis_inverted(self):
'''
View
1  src/ft2font.cpp
@@ -4,7 +4,6 @@
#include "mplutils.h"
#include <sstream>
-#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"
/*
Something went wrong with that request. Please try again.