diff --git a/hvplot/converter.py b/hvplot/converter.py index 361b55da5..50ff45987 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -3038,7 +3038,7 @@ def labels(self, x=None, y=None, data=None): text = self.kwds.get('text') if not text: - text = [c for c in data.columns if c not in (x, y)][0] + text = next((c for c in data.columns if c not in (x, y)), y) elif text not in data.columns: data = data.copy() template_str = text # needed for dask lazy compute diff --git a/hvplot/tests/testcharts.py b/hvplot/tests/testcharts.py index 00c502b77..90794cb6f 100644 --- a/hvplot/tests/testcharts.py +++ b/hvplot/tests/testcharts.py @@ -535,6 +535,17 @@ def test_labels_format_float(self): ] assert list(plot.data['label']) == ['-58.7E -34.58N', '-47.9E -15.78N', '-70.7E -33.45N'] + def test_labels_default_y(self): + edge_df = self.edge_df.copy().drop(columns=['Volume {m3}']) + plot = edge_df.hvplot.labels('Longitude', 'Latitude') + assert list(plot.dimensions()) == [ + Dimension('Longitude'), + Dimension('Latitude'), + Dimension('Latitude'), + ] + assert plot.kdims == ['Longitude', 'Latitude'] + assert plot.vdims == ['Latitude'] + def test_labels_by(self): plot = self.edge_df.hvplot.labels( 'Longitude', 'Latitude', text='{Longitude:.1f}E {Latitude:.2f}N', by='Volume {m3}'