from lets_plot import *
LetsPlot.setup_html()
df = {
'x': [1],
'y': [1]
}
# No label format
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10)
# Use number format
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10, label_format='.2f')
# Use string pattern
ggplot(df, aes('x','y')) + geom_text(aes(label='x'), size = 10, label_format='{.2f} Kg')
# 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)'))
geom_text()¶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)
gggrid([
text_plot(color='red', alpha=1),
text_plot(color='red', alpha=0)
]) + ggsize(800, 200)
# 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)
geom_label()¶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)
# 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)
# 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)