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

Bugfix plot 2d coords transpose #3934

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Bug fixes
By `Todd Jennings <https://github.com/toddrjen>`_
- Fix ``FacetGrid`` when ``vmin == vmax``. (:issue:`3734`)
By `Deepak Cherian <https://github.com/dcherian>`_
- Fix bug where plotting line plots with 2D coordinates depended on dimension
order. (:issue:`3933`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _infer_line_data(darray, x, y, hue):
otherindex = 1 if darray.dims.index(huename) == 0 else 0
otherdim = darray.dims[otherindex]
xplt = darray.transpose(otherdim, huename, transpose_coords=False)
yplt = yplt.transpose(otherdim, huename, transpose_coords=False)
else:
raise ValueError(
"For 2D inputs, hue must be a dimension"
Expand Down
11 changes: 11 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ def test_2d_coords_line_plot(self):
with pytest.raises(ValueError, match="For 2D inputs, hue must be a dimension"):
da.plot.line(x="lon", hue="lat")

def test_2d_coord_line_plot_coords_transpose_invariant(self):
# checks for bug reported in GH #3933
x = np.arange(10)
y = np.arange(20)
ds = xr.Dataset(coords={"x": x, "y": y})

for z in [ds.y + ds.x, ds.x + ds.y]:
ds = ds.assign_coords(z=z)
ds["v"] = ds.x + ds.y
ds["v"].plot.line(y="z", hue="x")

def test_2d_before_squeeze(self):
a = DataArray(easy_array((1, 5)))
a.plot()
Expand Down