{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from lets_plot import *\n", "from lets_plot.plot import geom_livemap\n", "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Exploring Minard's 1812 plot with lets-plot #" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cities = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/cities.csv')\n", "troops = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/troops.csv')\n", "temps = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/temps.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = ggplot(troops)\n", "\n", "plot += geom_path(aes(x='long', y='lat', group='group', color='direction', size='survivors'))\n", "plot += scale_size(range=(.5, 15))\n", "plot += scale_color_manual(values=[ \"#DFC17E\", \"#252523\" ])\n", "\n", "plot += geom_point(aes(x='long', y='lat'), data=cities, color='#BB0000')\n", "plot += geom_text(aes(x='long', y='lat', label='city'), data=cities, vjust='top', color='#BB0000')\n", "\n", "plot += labs(x='', y='')\n", "plot += theme(legend_position='none')\n", "plot += ggsize(800, 200)\n", "\n", "plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = ggplot(troops)\n", "\n", "plot += geom_livemap(location=[23.5, 53.4, 38.1, 56.3])\n", "\n", "plot += geom_path(aes(x='long', y='lat', group='group', color='direction', size='survivors'))\n", "plot += scale_size(range=(.5, 15))\n", "plot += scale_color_manual(values=[ '#DFC17E', '#252523' ])\n", "\n", "plot += geom_point(aes(x='long', y='lat'), data=cities, color='red')\n", "\n", "plot += labs(x='', y='')\n", "plot += theme(legend_position='none')\n", "\n", "plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Rude, but working properly version of the path\n", "\n", "dfs = [ troops[i:(i + 2)] for i in range(troops.shape[0] - 2) ]\n", "dfs = filter(lambda df: df['group'].iloc[0] == df['group'].iloc[1], dfs)\n", "\n", "plot = ggplot()\n", "\n", "MAX_SIZE = 15\n", "for df in dfs:\n", " plot += geom_path(\n", " aes(x='long', y='lat', group='group', color='direction'),\n", " data=df,\n", " size=MAX_SIZE*df['survivors'].iloc[0]/troops['survivors'].max(),\n", " color=('#DFC17E' if df['direction'].iloc[0] == 'A' else '#252523')\n", " )\n", "\n", "plot += geom_point(aes(x='long', y='lat'), data=cities, color='#BB0000')\n", "plot += geom_text(aes(x='long', y='lat', label='city'), data=cities, vjust='top', color='#BB0000')\n", "\n", "plot += labs(x='', y='')\n", "plot += theme(legend_position='none')\n", "plot += ggsize(800, 200)\n", "\n", "plot" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 2 }