Skip to content
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
2 changes: 1 addition & 1 deletion hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions hvplot/tests/testcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Comment on lines +546 to +547
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, is it ok for a holoviews element to have a dimension both in the kdims and vdims?

Copy link
Collaborator

@Azaya89 Azaya89 Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can if you pass them in directly:

import holoviews as hv
import pandas as pd

df = pd.DataFrame({
    'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
    'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
})

plot = hv.Points(df, ['lon', 'lat'], 'lon')
plot.dimensions()

[Dimension('lon'), Dimension('lat'), Dimension('lon')]

This is what is now achieved here via next((c for c in data.columns if c not in (x, y)), y), no? @ahuang11

Copy link
Collaborator Author

@ahuang11 ahuang11 Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost! Very close:

next((c for c in data.columns if c not in (x, y)), y) should default to y, which is:

import holoviews as hv
import pandas as pd

df = pd.DataFrame({
    'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
    'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
})

plot = hv.Points(df, ['lon', 'lat'], 'lat')  # lat not lon
plot.dimensions()

If df has an extra col, it'll use that:

import holoviews as hv
import pandas as pd

df = pd.DataFrame({
    'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
    'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
    'col': ['a', 'b', 'c', 'd', 'e']
})

plot = hv.Points(df, ['lon', 'lat'], 'col')
plot.dimensions()

And yes to Maxime's question:
image

Copy link
Member

@maximlt maximlt Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I saw the plot could be created but was wondering if it wouldn't mess up with other things in HoloViews like slicing data. Anyway, I don't think it's so important for this use case so I'll merge.


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