Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Dec 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/api/custom_projection_example.py
Expand Up @@ -262,25 +262,25 @@ def set_xlim(self, *args, **kwargs):
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0) Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
set_ylim = set_xlim 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 Override this method to change how the values are displayed in
the status bar. the status bar.


In this case, we want them to be displayed in degrees N/S/E/W. 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) lat = lat * (180.0 / np.pi)
if lat >= 0.0: if lat >= 0.0:
ns = 'N' ns = 'N'
else: else:
ns = 'S' ns = 'S'
if long >= 0.0: if lon >= 0.0:
ew = 'E' ew = 'E'
else: else:
ew = 'W' ew = 'W'
# \u00b0 : degree symbol # \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): class DegreeFormatter(Formatter):
""" """
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes.py
Expand Up @@ -2421,7 +2421,7 @@ def set_axis_bgcolor(self, color):
def invert_xaxis(self): def invert_xaxis(self):
"Invert the x-axis." "Invert the x-axis."
left, right = self.get_xlim() left, right = self.get_xlim()
self.set_xlim(right, left) self.set_xlim(right, left, auto=None)


def xaxis_inverted(self): def xaxis_inverted(self):
"""Returns *True* if the x-axis is inverted.""" """Returns *True* if the x-axis is inverted."""
Expand Down Expand Up @@ -2641,7 +2641,7 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
def invert_yaxis(self): def invert_yaxis(self):
"Invert the y-axis." "Invert the y-axis."
bottom, top = self.get_ylim() bottom, top = self.get_ylim()
self.set_ylim(top, bottom) self.set_ylim(top, bottom, auto=None)


def yaxis_inverted(self): def yaxis_inverted(self):
"""Returns *True* if the y-axis is inverted.""" """Returns *True* if the y-axis is inverted."""
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/projections/geo.py
Expand Up @@ -163,19 +163,19 @@ def set_xlim(self, *args, **kwargs):


set_ylim = set_xlim set_ylim = set_xlim


def format_coord(self, long, lat): def format_coord(self, lon, lat):
'return a format string formatting the coordinate' '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) lat = lat * (180.0 / np.pi)
if lat >= 0.0: if lat >= 0.0:
ns = 'N' ns = 'N'
else: else:
ns = 'S' ns = 'S'
if long >= 0.0: if lon >= 0.0:
ew = 'E' ew = 'E'
else: else:
ew = 'W' 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): def set_longitude_grid(self, degrees):
""" """
Expand Down Expand Up @@ -576,10 +576,10 @@ def transform_non_affine(self, xy):


lat = np.arcsin(cos_c*np.sin(clat) + lat = np.arcsin(cos_c*np.sin(clat) +
((y*sin_c*np.cos(clat)) / p)) ((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)) (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__ transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__


def inverted(self): def inverted(self):
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -419,6 +419,29 @@ def test_hexbin_extent():


ax.hexbin(x, y, extent=[.1, .3, .6, .7]) 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']) @image_comparison(baseline_images=['nonfinite_limits'])
def test_nonfinite_limits(): def test_nonfinite_limits():
x = np.arange(0., np.e, 0.01) x = np.arange(0., np.e, 0.01)
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Expand Up @@ -1389,7 +1389,7 @@ def invert_zaxis(self):
This function was added, but not tested. Please report any bugs. This function was added, but not tested. Please report any bugs.
""" """
bottom, top = self.get_zlim() bottom, top = self.get_zlim()
self.set_zlim(top, bottom) self.set_zlim(top, bottom, auto=None)


def zaxis_inverted(self): def zaxis_inverted(self):
''' '''
Expand Down
1 change: 0 additions & 1 deletion src/ft2font.cpp
Expand Up @@ -4,7 +4,6 @@
#include "mplutils.h" #include "mplutils.h"
#include <sstream> #include <sstream>


#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h" #include "numpy/arrayobject.h"


/* /*
Expand Down