3

How do I change fontsizes using holoviews or hvplot?

Here's a simple example of the plot I have:

# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas
hv.extension('bokeh', logo=False)

# create sample dataframe
df = pd.DataFrame({
    'col1': np.random.normal(size=30),
    'col2': np.random.normal(size=30),
})

# plot data with holoviews
my_plot = hv.Scatter(df, label='Scattering around')
Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96

1 Answers1

3

1) You can change fontsizes by using .opts(fontsize={}) on your plot, like so:

# change fontsizes for different parts of plot
my_plot.opts(fontsize={
    'title': 15, 
    'labels': 14, 
    'xticks': 10, 
    'yticks': 10,
})


2) With version >= 1.13 of holoviews you can scale all the fonts all at once and make legend, title, xticks larger with .opts(fontscale=1.5):

# make fonts all at once larger for your plot by the same scale
# here I've chosen fontscale=2, which makes all fonts 200% larger
my_plot.opts(fontscale=2)


3) If you would like to scale your fonts and you have a bokeh backend for your holoviews plot, you can do:

# scale fontsizes with 200%
my_plot.opts(fontsize={
    'title': '200%',
    'labels': '200%', 
    'ticks': '200%', 
})

More info on all the possible parts of which you can change the fontsize can be found here:
http://holoviews.org/user_guide/Customizing_Plots.html#Font-sizes

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
  • How does this work with hvplot? For example, neither, df.hvplot.labels(x='A',y='B',text='C',size=4) nor df.hvplot.labels(x='A',y='B',text='C',fontsize={'labels':4}) seems to have any effect on the labels size. – Nirjhor Chakraborty Mar 18 '20 at 15:31