{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# \"Bagging\" the munros into rectangular bins\n", "\n", "*A Munro (About this sound listen (help·info)) is a mountain in Scotland with a height over 3,000 feet (914 m). Munros are named after Sir Hugh Munro, 4th Baronet (1856–1919), who produced the first list of such hills, known as Munro's Tables, in 1891...* says Wikipedia, more in https://en.wikipedia.org/wiki/Munro.\n", "\n", "Let's show the possibility to plot histograms in the maps with the help of folium library." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Necessary import evil\n", "import pandas as pd\n", "import numpy as np\n", "import physt\n", "import physt.plotting\n", "physt.plotting.set_default_backend(\"folium\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightlonglat
0Ben Nevis1344.0-5.00352656.796834
1Ben Macdui [Beinn Macduibh]1309.0-3.66910057.070386
2Braeriach1296.0-3.72858157.078177
3Cairn Toul1291.0-3.71079057.054415
4Sgor an Lochain Uaine1258.0-3.72579757.058378
\n", "
" ], "text/plain": [ " name height long lat\n", "0 Ben Nevis 1344.0 -5.003526 56.796834\n", "1 Ben Macdui [Beinn Macduibh] 1309.0 -3.669100 57.070386\n", "2 Braeriach 1296.0 -3.728581 57.078177\n", "3 Cairn Toul 1291.0 -3.710790 57.054415\n", "4 Sgor an Lochain Uaine 1258.0 -3.725797 57.058378" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Read the data\n", "import pandas as pd\n", "munros = pd.read_csv(\"../physt/examples/munros.csv\")\n", "munros.head()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(282, 4)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# How many of them are there? Wikipedia says 282 (as of 2017)\n", "munros.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How many munros are in each 10' rectangle?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "hist = physt.h2(munros[\"lat\"], munros[\"long\"], \"fixed_width\", 1 / 6)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map = hist.plot()\n", "map" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Now, let's combine this information with positions of the 20 tallest\n", "import folium\n", "map = hist.plot()\n", "for i, row in munros.iloc[:20].iterrows():\n", " marker = folium.Marker([row[\"lat\"], row[\"long\"]], popup=\"{0} ({1} m)\".format(row[\"name\"], row[\"height\"]))\n", " marker.add_to(map)\n", "map" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "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.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }