import pandas as pd
from lets_plot.geo_data import *
from lets_plot import *
LetsPlot.setup_html()
mpg_df = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg_df
p = (ggplot(mpg_df, aes(x='displ', y='cty', fill='drv', size='hwy'))
+ scale_size(range=[5, 15], breaks=[15, 40])
+ ggsize(600, 350)
)
# Tooltips: split a line using '\n'
p + geom_point(shape=21, color='white',
tooltips=layer_tooltips()
.line('@manufacturer \n@model')
.line('@|@class')
.line('@|@year'))
# Use '\n' in 'format'
p + geom_point(shape=21,
color='white',
tooltips=layer_tooltips().format('^size', '{.0f} \n(mpg)'))
# Tooltip title
# Add title to default tooltip lines
p + geom_point(shape=21, color='white',
tooltips=layer_tooltips().title('@manufacturer @model'))
# Add title to user specified multiline tooltip
p + geom_point(shape=21,
color='white',
tooltips=layer_tooltips(['class', 'year']).title('@manufacturer @model'))
# Multi-line title
p + geom_point(shape=21,
color='white',
tooltips=layer_tooltips()
.line('@|@class')
.line('drive train|@drv')
.line('@|@year')
.title('Car info: \n@manufacturer @model'))
cities = pd.read_csv ("../data/cities.csv")
cities.head()
czech_cities = cities.loc[cities['coutry_id'] == 144]
czech_cities
country_gcoder = geocode_countries(['Czech'])
country_gcoder.get_geocodes()
# Automatic word wrap:
# the value string is limited by the number of characters in it,
# and description will be split into multiple lines.
(ggplot()
+ geom_livemap(location=[15.78,49.35], zoom=6)
+ geom_polygon(aes(fill='country'),
data=country_gcoder.get_boundaries(),
alpha=.2)
+ geom_point(aes('longitude', 'latitude', color='name'),
data=czech_cities,
size=4,
tooltips=layer_tooltips()
.title('@name')
.line('Longitude|@longitude')
.line('Latitude|@latitude')
.line('Description|@text'))
+ theme(legend_position='none')
)