In [1]:
from lets_plot import *

LetsPlot.setup_html() 
In [2]:
df = {
    'x': [1],
    'y': [1]
}
In [3]:
# No label format
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10)
Out[3]:
In [4]:
# Use number format
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10, label_format='.2f')
Out[4]:
In [5]:
# Use string pattern 
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10, label_format='{.2f} Kg')
Out[5]:
In [6]:
# Add tooltip
ggplot(df, aes('x','y')) \
  + geom_text(aes(label='x'), size = 10, label_format='{.2f} Kg', \
                tooltips=layer_tooltips().line('position|(x=$x, y=$y)'))
Out[6]:

Apply Alpha

geom_text()
In [7]:
def text_plot(color, alpha):
    return ggplot(df, aes('x','y')) + geom_text(x=0, y=0, label='Lorem ipsum', size=14, color=color, alpha=alpha)
In [8]:
gggrid([
    text_plot(color='red', alpha=1),
    text_plot(color='red', alpha=0)
]) + ggsize(800, 200)
Out[8]:
In [9]:
# defined aes alpha has priority over color's alpha

gggrid([
    text_plot(color='rgba(255,0,0,0.5)', alpha=None),
    text_plot(color='rgba(255,0,0,0.5)', alpha=1)
]) + ggsize(800, 200)
Out[9]:
geom_label()
In [10]:
def label_plot(fill, color, alpha, alpha_stroke=None):
    return ggplot(df, aes('x','y')) + \
              geom_label(label='Lorem ipsum', size=14, label_size=4, 
                         fill=fill, color=color, 
                         alpha=alpha, alpha_stroke=alpha_stroke)
In [11]:
# alpha is applied to fill, not to color

gggrid([
    label_plot(fill='light_blue', color='red', alpha=1),
    label_plot(fill='light_blue', color='red', alpha=0)
]) + ggsize(800, 200)
Out[11]:
In [12]:
# Activate the effect of alpha on color: 
# rgba or alpha_stroke=True

gggrid([
    label_plot(fill='light_blue', color='rgba(255,0,0,0.5)', alpha=None),
    label_plot(fill='light_blue', color='red', alpha=0.1, alpha_stroke=True)
]) + ggsize(800, 200)
Out[12]: