from lets_plot import *
import pandas as pd
LetsPlot.setup_html()
ggplot() + geom_label(x=0, y=0, label='Lorem ipsum', size=14) + ggsize(500, 200)
ggplot() + geom_label(x=0, y=0,
label='Lorem ipsum',
size=14,
fill='#edf8e9',
color='#238b45',
fontface='bold',
label_padding=1.0,
label_r=0.5,
label_size=2.0
) + ggsize(500, 200)
families = [
"Arial",
"Calibri",
"Garamond",
"Geneva",
"Georgia",
"Helvetica",
"Lucida Grande",
"Rockwell",
"Times New Roman",
"Verdana",
"sans-serif",
"serif",
"monospace"
]
ggplot() + geom_label(aes(y=list(range(len(families))), label=families, family=families), size=10,
label_padding=0,
label_r=0)
d = {
'hjust': [0, 0.5, 1],
'vjust': [0, 0.5, 1],
'angle': [0, 45, 90],
'text' : ['Text']
}
from itertools import product
td = pd.DataFrame(product(*d.values()), columns=d.keys())
(ggplot(td, aes(x='hjust', y='vjust')) +
geom_point(size=3) +
geom_label(aes(label='text', angle='angle', hjust='hjust', vjust='vjust'), size=9) +
facet_grid(y='angle') +
scale_x_continuous(breaks=[0, 0.5, 1], expand=[0.1]) +
scale_y_continuous(breaks=[0, 0.5, 1], expand=[0.0, 0.5]) +
theme_classic() + theme(panel_border=element_rect(size=1))
)
mpg = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv")
mpg.head()
miles per gallon | number of cylinders | engine displacement (cu. inches) | engine horsepower | vehicle weight (lbs.) | time to accelerate (sec.) | model year | origin of car | vehicle name | |
---|---|---|---|---|---|---|---|---|---|
0 | 18.0 | 8 | 307.0 | 130 | 3504 | 12.0 | 70 | US | chevrolet chevelle malibu |
1 | 15.0 | 8 | 350.0 | 165 | 3693 | 11.5 | 70 | US | buick skylark 320 |
2 | 18.0 | 8 | 318.0 | 150 | 3436 | 11.0 | 70 | US | plymouth satellite |
3 | 16.0 | 8 | 304.0 | 150 | 3433 | 12.0 | 70 | US | amc rebel sst |
4 | 17.0 | 8 | 302.0 | 140 | 3449 | 10.5 | 70 | US | ford torino |
p = ggplot(mpg.head(30), aes('vehicle weight (lbs.)', 'miles per gallon', label='vehicle name'))
p + geom_label()
from lets_plot.mapping import as_discrete
p + geom_label(aes(fill = as_discrete('number of cylinders', order=1)),
color = 'white',
fontface = 'bold'
) + ggsize(800,400)
from lets_plot.geo_data import *
gcoder = geocode_states('us-48').inc_res()
gplot = (ggplot() +
geom_polygon(aes(fill='state'),
data=gcoder.get_boundaries(),
show_legend=False,
color="white",
tooltips='none') +
coord_map() +
theme(axis='blank', panel_grid="blank") +
scale_fill_brewer(name="state", palette="Dark2") +
ggsize(900, 500))
gplot + geom_label(aes(label='state'), data=gcoder.get_centroids(), size=6)
The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).