Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,10 @@ 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]
if len(data.columns) > 2:
text = next(c for c in data.columns if c not in (x, y))
else:
text = y
elif text not in data.columns:
data = data.copy()
template_str = text # needed for dask lazy compute
Expand Down
9 changes: 9 additions & 0 deletions hvplot/tests/testcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,15 @@ 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'])
plot = edge_df.hvplot.labels('Longitude', 'Latitude')
assert list(plot.dimensions()) == [
Dimension('Longitude'),
Dimension('Latitude'),
]
assert list(plot.data['label']) == ['-34.58', '15.78', '-33.45']

def test_labels_by(self):
plot = self.edge_df.hvplot.labels(
'Longitude', 'Latitude', text='{Longitude:.1f}E {Latitude:.2f}N', by='Volume {m3}'
Expand Down
Loading