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

plot.imshow now obeys 'origin' kwarg. #2396

Merged
merged 1 commit into from Sep 6, 2018
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
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Expand Up @@ -71,6 +71,10 @@ Enhancements
Bug fixes
~~~~~~~~~

- ``xarray.plot.imshow()`` correctly uses the ``origin`` argument.
(:issue:`2379`)
By `Deepak Cherian <https://github.com/dcherian>`_.

- Fixed ``DataArray.to_iris()`` failure while creating ``DimCoord`` by
falling back to creating ``AuxCoord``. Fixed dependency on ``var_name``
attribute being set.
Expand Down
15 changes: 9 additions & 6 deletions xarray/plot/plot.py
Expand Up @@ -619,7 +619,7 @@ def _plot2d(plotfunc):
@functools.wraps(plotfunc)
def newplotfunc(darray, x=None, y=None, figsize=None, size=None,
aspect=None, ax=None, row=None, col=None,
col_wrap=None, xincrease=True, yincrease=True,
col_wrap=None, xincrease=None, yincrease=None,
add_colorbar=None, add_labels=True, vmin=None, vmax=None,
cmap=None, center=None, robust=False, extend=None,
levels=None, infer_intervals=None, colors=None,
Expand Down Expand Up @@ -789,7 +789,7 @@ def newplotfunc(darray, x=None, y=None, figsize=None, size=None,
@functools.wraps(newplotfunc)
def plotmethod(_PlotMethods_obj, x=None, y=None, figsize=None, size=None,
aspect=None, ax=None, row=None, col=None, col_wrap=None,
xincrease=True, yincrease=True, add_colorbar=None,
xincrease=None, yincrease=None, add_colorbar=None,
add_labels=True, vmin=None, vmax=None, cmap=None,
colors=None, center=None, robust=False, extend=None,
levels=None, infer_intervals=None, subplot_kws=None,
Expand Down Expand Up @@ -857,10 +857,8 @@ def imshow(x, y, z, ax, **kwargs):
left, right = x[0] - xstep, x[-1] + xstep
bottom, top = y[-1] + ystep, y[0] - ystep

defaults = {'extent': [left, right, bottom, top],
'origin': 'upper',
'interpolation': 'nearest',
}
defaults = {'origin': 'upper',
'interpolation': 'nearest'}

if not hasattr(ax, 'projection'):
# not for cartopy geoaxes
Expand All @@ -869,6 +867,11 @@ def imshow(x, y, z, ax, **kwargs):
# Allow user to override these defaults
defaults.update(kwargs)

if defaults['origin'] == 'upper':
defaults['extent'] = [left, right, bottom, top]
else:
defaults['extent'] = [left, right, top, bottom]

if z.ndim == 3:
# matplotlib imshow uses black for missing data, but Xarray makes
# missing data transparent. We therefore add an alpha channel if
Expand Down
11 changes: 11 additions & 0 deletions xarray/tests/test_plot.py
Expand Up @@ -1284,6 +1284,17 @@ def test_regression_rgb_imshow_dim_size_one(self):
da = DataArray(easy_array((1, 3, 3), start=0.0, stop=1.0))
da.plot.imshow()

def test_imshow_origin_kwarg(self):
da = DataArray(easy_array((5, 5, 3), start=-0.6, stop=1.4))
da.plot.imshow(origin='upper')
assert plt.xlim()[0] < 0
assert plt.ylim()[1] < 0

plt.clf()
da.plot.imshow(origin='lower')
assert plt.xlim()[0] < 0
assert plt.ylim()[0] < 0


class TestFacetGrid(PlotTestCase):
def setUp(self):
Expand Down