Customizing fonts#
You can set font size, face, and family using theme.
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
print(df.shape)
df.head()
(234, 12)
| Unnamed: 0 | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
| 1 | 2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
| 2 | 3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
| 3 | 4 | audi | a4 | 2.0 | 2008 | 4 | auto(av) | f | 21 | 30 | p | compact |
| 4 | 5 | audi | a4 | 2.8 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | compact |
Default font#
p = ggplot(df, aes('cty', 'hwy', color='drv')) + \
geom_point(tooltips=layer_tooltips()
.title('@manufacturer @model')
.line('@|@class')
.format('@year', 'd')
.line('@|@year')) + \
labs(title='The plot title',
subtitle='The plot subtitle',
caption='The plot caption',
color='Drive type')
p
Change font face and size#
p + theme(title=element_text(size=18),
plot_title=element_text(face='bold'),
plot_caption=element_text(size=12, face='italic'),
axis_text=element_text(size=14, face='italic'),
tooltip_text=element_text(size=15))
p + theme(plot_subtitle=element_text(face='bold_italic'),
plot_caption=element_text(face='italic'),
legend_title=element_text(face='bold'),
legend_text=element_text(face='italic'),
axis_title=element_text(face='bold'),
axis_text=element_text(face='bold_italic'),
tooltip_text=element_text(face='italic'))
# tooltip_text will be also applied to axes tooltips ('italic');
# title and label in general tooltip are bold by default -> the result for them is 'bold_italic'
Change font family#
Let’s change font family everywhere using text parameter.
p + theme(text=element_text(family='Times New Roman', size=15))