Labels#

Download this notebook from GitHub (right-click to download).


import hvplot.pandas  # noqa

labels are mostly useful when overlaid on top of other plots. For instance in this case we will plot some capitals as points and then overlay (using the * operator) labels.

import pandas as pd

df = pd.DataFrame(
    {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
     'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
     'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
     'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]})
df
City Country Latitude Longitude
0 Buenos Aires Argentina -34.58 -58.66
1 Brasilia Brazil -15.78 -47.91
2 Santiago Chile -33.45 -70.66
3 Bogota Colombia 4.60 -74.08
4 Caracas Venezuela 10.48 -66.86
df.hvplot.points(x='Longitude', y='Latitude', padding=0.2, hover_cols='all', width=300) * \
df.hvplot.labels(x='Longitude', y='Latitude', text='City', text_baseline='bottom', hover=False) * \
df.hvplot.labels(x='Longitude', y='Latitude', text='Country', text_baseline='top', hover=False)

It’s also possible to provide a template string containing the names of the columns and reduce the font size.

df.hvplot.points(x='Longitude', y='Latitude', padding=0.2, hover_cols='all', width=300) * \
df.hvplot.labels(x='Longitude', y='Latitude', text='@{City}, {Country}', text_baseline='bottom', text_font_size='10px', hover=False)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).