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.
Added in version 0.12.0. |
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='78ebf623-b188-48f3-8e02-c4b1639fbd9e', ...),
'xaxis': LinearAxis(id='45387974-e1d3-43ac-b5a0-52168b40a409', ...),
'x_range': Range1d(id='bb098bdb-7004-4597-8bb1-5eab809a2ce1', ...),
'extra_x_ranges': {},
'extra_x_scales': {},
'yaxis': LinearAxis(id='b927cbd2-8284-4b72-ab82-a39b0ba73c80', ...),
'y_range': Range1d(id='fc8472eb-ad67-4eb4-9d35-0e80fe631978', ...),
'extra_y_ranges': {},
'extra_y_scales': {},
'plot': figure(id='0945f6e3-f2fa-43be-8d79-3526f1c9d3d7', ...),
'previous_id': 5043849264,
'source': ColumnDataSource(id='a13a8f7f-e75d-4ee6-8c7c-30a15c1aac59', ...),
'cds': ColumnDataSource(id='a13a8f7f-e75d-4ee6-8c7c-30a15c1aac59', ...),
'selected': Selection(id='1b8c806f-6319-49f4-9123-482e99d75596', ...),
'glyph': Scatter(id='6ca1b047-437b-4284-b4f3-bfc97d44751d', ...),
'glyph_renderer': GlyphRenderer(id='ac299617-5952-4a42-b913-891d99f6f00d', ...)}
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 0x138171810>,
'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)