import pandas as pd
from lets_plot import *
from lets_plot.plot import geom_livemap
LetsPlot.setup_html()
cities = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/cities.csv')
troops = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/troops.csv')
temps = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/temps.csv')
plot = ggplot(troops)
plot += geom_path(aes(x='long', y='lat', group='group', color='direction', size='survivors'))
plot += scale_size(range=(.5, 15))
plot += scale_color_manual(values=[ "#DFC17E", "#252523" ])
plot += geom_point(aes(x='long', y='lat'), data=cities, color='#BB0000')
plot += geom_text(aes(x='long', y='lat', label='city'), data=cities, vjust='top', color='#BB0000')
plot += labs(x='', y='')
plot += theme(legend_position='none')
plot += ggsize(800, 200)
plot
plot = ggplot(troops)
plot += geom_livemap(location=[23.5, 53.4, 38.1, 56.3])
plot += geom_path(aes(x='long', y='lat', group='group', color='direction', size='survivors'))
plot += scale_size(range=(.5, 15))
plot += scale_color_manual(values=[ '#DFC17E', '#252523' ])
plot += geom_point(aes(x='long', y='lat'), data=cities, color='red')
plot += labs(x='', y='')
plot += theme(legend_position='none')
plot
# Rude, but working properly version of the path
dfs = [ troops[i:(i + 2)] for i in range(troops.shape[0] - 2) ]
dfs = filter(lambda df: df['group'].iloc[0] == df['group'].iloc[1], dfs)
plot = ggplot()
MAX_SIZE = 15
for df in dfs:
plot += geom_path(
aes(x='long', y='lat', group='group', color='direction'),
data=df,
size=MAX_SIZE*df['survivors'].iloc[0]/troops['survivors'].max(),
color=('#DFC17E' if df['direction'].iloc[0] == 'A' else '#252523')
)
plot += geom_point(aes(x='long', y='lat'), data=cities, color='#BB0000')
plot += geom_text(aes(x='long', y='lat', label='city'), data=cities, vjust='top', color='#BB0000')
plot += labs(x='', y='')
plot += theme(legend_position='none')
plot += ggsize(800, 200)
plot