Styling Options#
Note
These are the styling options shared by all the supported plotting backends. Backend-specific options can be found on the reference page of each plotting method (e.g. hvplot.hvPlot.scatter()
) or by executing hvplot.help('scatter', docstring=False, generic=False, style=True)
.
Visual styling options to adjust colors, fonts, and other aesthetic elements of the plot:
Parameters |
Description |
---|---|
backend_opts (dict or None, optional) |
A dictionary of custom options to apply to the plot or subcomponents of
the plot. The keys in the dictionary mirror attribute access on the
underlying plotting backend objects stored in the plot’s handles, e.g.
|
fontscale (number) |
Scales the size of all fonts by the same amount, e.g. fontscale=1.5 enlarges all fonts (title, xticks, labels etc.) by 50%. |
fontsize (number or dict or None, default=None) |
Set title, label and legend text to the same fontsize. Finer control
by using a dict: |
grid (bool or None, default=None) |
Whether to show a grid. |
backend_opts
#
hvPlot offers many options to customize a plot. Yet, sometimes this is not enough, in which case backend_opts
offers a powerful mechanism to customize many properties of the plot objects created internally by HoloViews (Bokeh models, Matplotlib figure and axis, etc.). This option accepts a dictionary whose keys are string accessors, i.e. they mirror attribute access on these plot objects. The values of this dictionary are the values to set.
The objects that can be targeted via this accessor pattern are those referenced in the HoloViews plot handles
dictionary. Usually that would be the plot
key for Bokeh giving access to the figure
object, and the fig
key for Matplotlib giving access to the Figure
object. Note that accessors starting with plot
for Bokeh and fig
for Matplotlib can omit these terms (e.g. xgrid.grid_line_color
instead of plot.xgrid.grid_line_colore
for Bokeh).
Let’s start with a Bokeh example where we set properties of the grid, the x- and y-axis, and hover. These options cannot be directly customized with the current hvPlot’s API.
import hvplot.pandas # noqa
df = hvplot.sampledata.penguins("pandas")
plot = df.hvplot.scatter(
x="bill_length_mm", y="bill_depth_mm", color="black",
backend_opts={
"plot.xgrid.grid_line_color": "grey",
"plot.xgrid.grid_line_dash": "dotted",
"plot.xaxis.axis_label_text_font_style": "bold",
"plot.yaxis.axis_label_text_font_style": "bold",
"hover.attachment": "vertical",
}
)
plot
With the code below, we can see all the handles we could have referenced for this plot (other plots may have different handles).
import holoviews as hv
hv.renderer('bokeh').get_plot(plot).handles
{'hover': HoverTool(id='4325a1ee-799e-4b9b-984d-a5c48cfa22a2', ...),
'xaxis': LinearAxis(id='d7502344-058d-4c68-bf92-0b5572756b01', ...),
'x_range': Range1d(id='f583ed8a-9f77-4976-a4c3-c2ac2f38aa91', ...),
'extra_x_ranges': {},
'extra_x_scales': {},
'yaxis': LinearAxis(id='2243ad70-923f-4663-bcb7-ead25153306a', ...),
'y_range': Range1d(id='0acbd63b-f0ab-49e5-b0bf-5f401f11babd', ...),
'extra_y_ranges': {},
'extra_y_scales': {},
'plot': figure(id='3b8a398f-4c00-4091-8f38-1767a832794f', ...),
'previous_id': 4673038864,
'source': ColumnDataSource(id='181442e3-bb2a-4821-bf4d-c2c2cd2152a3', ...),
'cds': ColumnDataSource(id='181442e3-bb2a-4821-bf4d-c2c2cd2152a3', ...),
'selected': Selection(id='a51cbfa4-6bee-43ab-932d-5a99da56f695', ...),
'glyph': Scatter(id='b92d39be-a1ef-40b5-938d-ff8ae5c1f0bb', ...),
'glyph_renderer': GlyphRenderer(id='1fb6dbad-37c1-4e71-b835-64121935da8c', ...)}
We can see the Bokeh property grid_line_color
exists and has been correctly set.
hv.renderer('bokeh').get_plot(plot).handles['plot'].xgrid.grid_line_color
'grey'
In this Matplotlib example we disable the plot frame. Note that we could also have written the accessor as 'axes.set_frame_on'
(which is the method called internally by HoloViews).
import hvplot.pandas # noqa
hv.extension("matplotlib")
df = hvplot.sampledata.penguins("pandas")
plot = df.hvplot.scatter(
x="bill_length_mm", y="bill_depth_mm",
backend_opts={"axes.frame_on": False}
)
plot
Here’s the list of handles for this plot.
hv.renderer('matplotlib').get_plot(plot).handles
{'fig': <Figure size 933.333x933.333 with 1 Axes>,
'axis': <Axes: xlabel='bill_length_mm', ylabel='bill_depth_mm'>,
'bbox_extra_artists': [],
'artist': <matplotlib.collections.PathCollection at 0x11a166610>,
'title': Text(0.5, 1.0, '')}
We can see the Matplotlib method set_frame_on
exists and has been correctly executed.
hv.renderer('matplotlib').get_plot(plot).handles['axis'].set_frame_on
<bound method _AxesBase.set_frame_on of <Axes: xlabel='bill_length_mm', ylabel='bill_depth_mm'>>
hv.renderer('matplotlib').get_plot(plot).handles['axis'].get_frame_on()
False
See also
The legend_opts
option to customize specifically the styling of the legend.
fontscale
#
The fontscale
option scales all the fonts in the plot by the provided numeric factor. For example, setting fontscale=1.5
enlarges the title, tick labels, and axis labels by 50%. This is useful when you want to emphasize text for presentations or detailed viewing.
import hvplot.pandas # noqa
df = hvplot.sampledata.penguins("pandas")
df.hvplot.scatter(
x='bill_length_mm', y='bill_depth_mm', by='species',
fontscale=1.5, title="Penguins Species",
)
fontsize
#
The fontsize
option sets the font size for different text elements in the plot. It can be:
A single value (e.g.
12
) to apply to all text elements.A dictionary to control specific elements like the title, axis labels, and ticks.
Example:{'title': '15pt', 'xlabel': '12pt', 'ylabel': '12pt', 'ticks': 10}
This option is useful for precise text control in reports, presentations, and dashboards.
Note
Backend-specific behavior
The Bokeh backend supports both numeric values and strings with units like
'12pt'
or'10px'
.The Matplotlib backend only accepts numeric values. Using strings like
'14pt'
will not work.
To ensure compatibility across backends, prefer using numbers unless you’re specifically targeting Bokeh.
Bokeh backend
import hvplot.pandas # noqa
df = hvplot.sampledata.penguins("pandas")
df.hvplot.scatter(
x='bill_length_mm', y='bill_depth_mm', by='species',
fontsize={'title': '16pt', 'xlabel': '12pt', 'ylabel': '14pt', 'ticks': 10},
title="Penguins Measurements by Species"
)
Matplotlib backend
import hvplot.pandas # noqa
hvplot.extension('matplotlib')
df = hvplot.sampledata.penguins("pandas")
df.hvplot.scatter(
x='bill_length_mm', y='bill_depth_mm', by='species',
fontsize={'title': 22, 'xlabel': 16, 'ylabel': 18, 'ticks': 12},
title="Penguins Measurements by Species"
)
grid
#
Turns grid lines on or off behind your data. By default grids are disabled; use grid=True
to draw horizontal and vertical lines at each major tick mark.
import hvplot.pandas # noqa
df = hvplot.sampledata.stocks("pandas", engine_kwargs={"index_col" : "date"})
plot1 = df.hvplot(group_label="Company", width=400, title="Default: grid=False")
plot2 = df.hvplot(group_label="Company", grid=True, width=400, title="grid=True")
(plot1 + plot2).cols(1)