hvPlot.labels#
- hvPlot.labels(x=None, y=None, text=None, **kwds)[source]#
Labels plot.
labels are mostly useful when overlaid on top of other plots using the * operator.
Reference: https://hvplot.holoviz.org/ref/api/manual/hvplot.hvPlot.labels.html
Plotting options: https://hvplot.holoviz.org/ref/plotting_options/index.html
- Parameters:
- xstring, optional
The coordinate variable along the x-axis
- ystring, optional
The coordinate variable along the y-axis
- textstring, optional
The column to draw the text labels from; itβs also possible to provide a template string containing the column names to automatically format the text, e.g. β{col1}, {col2}β.
- **kwdsoptional
Additional keywords arguments are documented in Plotting Options. Run
hvplot.help('labels')
for the full method documentation.
- Returns:
holoviews.element.Labels
/ Panel objectYou can print the object to study its composition and run:
import holoviews as hv hv.help(the_holoviews_object)
to learn more about its parameters and options.
References
Backend-specific styling options#
angle, background_fill_alpha, background_fill_color, background_hatch_alpha, background_hatch_color, background_hatch_extra, background_hatch_pattern, background_hatch_scale, background_hatch_weight, border_alpha, border_color, border_line_alpha, border_line_cap, border_line_color, border_line_dash, border_line_dash_offset, border_line_join, border_line_width, border_radius, cmap, muted, text_align, text_alpha, text_baseline, text_color, text_font, text_font_size, text_font_style, visible
alpha, c, cmap, color, family, horizontalalignment, rotation, s, size, verticalalignment, visible, weight
Examples#
Basic points plot with labels#
This example shows how to overlay textual labels (e.g., a city name) on a 2D scatter plot. In order to avoid the labels being overlaid with the markers, the styling option text_baseline
is set to 'bottom'
, declaring that each label should be displayed above the point location.
import hvplot.pandas
import pandas as pd
df = pd.DataFrame({
'city': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
'country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
'lat': [-34.58, -15.78, -33.45, 4.60, 10.48],
'lon': [-58.66, -47.91, -70.66, -74.08, -66.86],
})
df.hvplot.points(x='lon', y='lat') * \
df.hvplot.labels(x='lon', y='lat', text='city', text_baseline='bottom', hover=False, padding=0.2)
Labels defined with a template string#
This example shows how to use a template string for the text parameter to label each earthquake with both its location and magnitude.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
# Use only high-magnitude earthquakes to reduce clutter
df = df[df.mag > 6]
df.hvplot.points(x="lon", y="lat") * \
df.hvplot.labels(
x="lon", y="lat",
text="{place}\nMag: {mag:.1f}", text_align="left",
text_font_size="8pt", padding=2,
)