Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Bug fixes
from higher frequencies to lower frequencies. Datapoints outside the bounds
of the original time coordinate are now filled with NaN (:issue:`2197`). By
`Spencer Clark <https://github.com/spencerkclark>`_.
- Line plots with the `x` argument set to a coord now plot the correct data.
(:issue:`27251). By `Tom Nicholas <http://github.com/TomNicholas>`_.

.. _whats-new.0.11.3:

Expand All @@ -67,7 +69,7 @@ Bug fixes
(e.g. '2000-01-01T00:00:00-05:00') no longer raises an error
(:issue:`2649`). By `Spencer Clark <https://github.com/spencerkclark>`_.
- Fixed performance regression with ``open_mfdataset`` (:issue:`2662`).
By `Tom Nicholas <http://github.com/TomNicholas>`_.

- Fixed supplying an explicit dimension in the ``concat_dim`` argument to
to ``open_mfdataset`` (:issue:`2647`).
By `Ben Root <https://github.com/WeatherGod>`_.
Expand Down
14 changes: 9 additions & 5 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ def _infer_line_data(darray, x, y, hue):
'for line plots.')

if ndims == 1:
dim, = darray.dims # get the only dimension name
huename = None
hueplt = None
huelabel = ''

if (x is None and y is None) or x == dim:
xplt = darray[dim]
if x is not None:
xplt = darray[x]
yplt = darray

else:
yplt = darray[dim]
elif y is not None:
xplt = darray
yplt = darray[y]

else: # Both x & y are None
dim = darray.dims[0]
xplt = darray[dim]
yplt = darray

else:
if x is None and y is None and hue is None:
Expand Down
15 changes: 15 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pandas as pd
import pytest
from numpy.testing import assert_array_equal

import xarray as xr
import xarray.plot as xplt
Expand Down Expand Up @@ -140,6 +141,20 @@ def test_1d_x_y_kw(self):
with raises_regex(ValueError, 'None'):
da.plot(x='z', y='f')

# Test for bug in GH issue #2725
def test_infer_line_data(self):
current = DataArray(name='I', data=np.array([5, 8]), dims=['t'],
coords={'t': (['t'], np.array([0.1, 0.2])),
'V': (['t'], np.array([100, 200]))})

# Plot current against voltage
line = current.plot.line(x='V')[0]
assert_array_equal(line.get_xdata(), current.coords['V'].values)

# Plot current against time
line = current.plot.line()[0]
assert_array_equal(line.get_xdata(), current.coords['t'].values)

def test_2d_line(self):
with raises_regex(ValueError, 'hue'):
self.darray[:, :, 0].plot.line()
Expand Down