Text Setting for Annotations

Use the label_text parameter in theme() to set basic text settings for annotations, using the element_text() function with the following parameters:

  • family - font family;
  • face - font face ("plain", "italic", "bold", "bold_italic");
  • size - text size, can also be specified via layer_labels().size();
  • color - text color.
In [1]:
import pandas as pd

from lets_plot import *
In [2]:
LetsPlot.setup_html()
In [3]:
mpg_df = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg_df.head(4)
Out[3]:
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
In [4]:
label_text_opts = element_text(family='Rockwell', face='bold', size=16, color='#542788')

Configure Text Labels for Bar Plot

In [5]:
ggplot(mpg_df) + \
    geom_bar(aes('class', fill='class'), labels=layer_labels().line('@..sumpct..')) + \
    theme(label_text=label_text_opts)
Out[5]:

Configure Text Labels for Pie Chart

In [6]:
ggplot(mpg_df) + \
    geom_pie(aes(fill='class'), size=26, hole=0.3, labels=layer_labels().line('@..proppct..')) + \
    theme_void() + \
    theme(label_text=label_text_opts)
Out[6]: