{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Instructions for Google Colab:\n",
    "# 1. Uncomment the following line\n",
    "# 2. Run it\n",
    "# 3. Restart runtime (Runtime -> Restart runtime)\n",
    "# 4. Comment it again\n",
    "#!pip install -e \"git+https://github.com/marceloprates/prettymaps#egg=prettymaps\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# prettymaps\n",
    "\n",
    "A minimal Python library to draw customized maps from [OpenStreetMap](https://www.openstreetmap.org/#map=12/11.0733/106.3078) created using the [osmnx](https://github.com/gboeing/osmnx), [matplotlib](https://matplotlib.org/), [shapely](https://shapely.readthedocs.io/en/stable/index.html) and [vsketch](https://github.com/abey79/vsketch) packages.\n",
    "\n",
    "![](https://github.com/marceloprates/prettymaps/raw/main/prints/heerhugowaard.png)\n",
    "\n",
    "\n",
    "This work is [licensed](LICENSE) under a GNU Affero General Public License v3.0 (you can make commercial use, distribute and modify this project, but must **disclose** the source code with the license and copyright notice)\n",
    "\n",
    "## Note about crediting and NFTs:\n",
    "- Please keep the printed message on the figures crediting my repository and OpenStreetMap ([mandatory by their license](https://www.openstreetmap.org/copyright)).\n",
    "- I am personally **against** NFTs for their [environmental impact](https://earth.org/nfts-environmental-impact/), the fact that they're a [giant money-laundering pyramid scheme](https://twitter.com/smdiehl/status/1445795667826208770) and the structural incentives they create for [theft](https://twitter.com/NFTtheft) in the open source and generative art communities.\n",
    "- **I do not authorize in any way this project to be used for selling NFTs**, although I cannot legally enforce it. **Respect the creator**.\n",
    "- The [AeternaCivitas](https://magiceden.io/marketplace/aeterna_civitas) and [geoartnft](https://www.geo-nft.com/) projects have used this work to sell NFTs and refused to credit it. See how they reacted after being exposed: [AeternaCivitas](etc/NFT_theft_AeternaCivitas.jpg), [geoartnft](etc/NFT_theft_geoart.jpg).\n",
    "- **I have closed my other generative art projects on Github and won't be sharing new ones as open source to protect me from the NFT community**.\n",
    "\n",
    "<a href='https://ko-fi.com/marceloprates_' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>\n",
    "\n",
    "## As seen on [Hacker News](https://web.archive.org/web/20210825160918/https://news.ycombinator.com/news):\n",
    "![](https://github.com/marceloprates/prettymaps/raw/main/prints/hackernews-prettymaps.png)\n",
    "\n",
    "## [prettymaps subreddit](https://www.reddit.com/r/prettymaps_/)\n",
    "## [Google Colaboratory Demo](https://colab.research.google.com/github/marceloprates/prettymaps/blob/master/notebooks/examples.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Installation\n",
    "\n",
    "OBS. I'm trying to solve a dependency issue with [vsketch](https://vsketch.readthedocs.io/en/latest/install.html) before publishing prettymaps v0.1.3, so, for now, please install directly from GitHub."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Install locally:\n",
    "Install prettymaps with:\n",
    "\n",
    "```\n",
    "pip install git+https://github.com/marceloprates/prettymaps\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Install on Google Colaboratory:\n",
    "\n",
    "Install prettymaps with:\n",
    "\n",
    "```\n",
    "!pip install -e \"git+https://github.com/marceloprates/prettymaps#egg=prettymaps\"\n",
    "```\n",
    "\n",
    "Then **restart the runtime** (Runtime -> Restart Runtime) before importing prettymaps"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plotting with prettymaps is very simple. Run:\n",
    "```python\n",
    "prettymaps.plot(your_query)\n",
    "```\n",
    "\n",
    "**your_query** can be:\n",
    "1. An address (Example: \"Porto Alegre\"),\n",
    "2. Latitude / Longitude coordinates (Example: (-30.0324999, -51.2303767))\n",
    "3. A custom boundary in GeoDataFrame format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1232464 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import prettymaps\n",
    "\n",
    "plot = prettymaps.plot('Stad van de Zon, Heerhugowaard, Netherlands')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also choose from different \"presets\" (parameter combinations saved in JSON files)\n",
    "\n",
    "See below an example using the \"minimal\" preset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 578120 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    'Stad van de Zon, Heerhugowaard, Netherlands',\n",
    "    preset = 'minimal'\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run\n",
    "\n",
    "```python\n",
    "prettymaps.presets()\n",
    "```\n",
    "\n",
    "to list all available presets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>preset</th>\n",
       "      <th>params</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>barcelona</td>\n",
       "      <td>{'layers': {'perimeter': {'circle': False}, 's...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>barcelona-plotter</td>\n",
       "      <td>{'layers': {'streets': {'width': {'primary': 5...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>cb-bf-f</td>\n",
       "      <td>{'layers': {'streets': {'width': {'trunk': 6, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>default</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>heerhugowaard</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>macao</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'cust...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>minimal</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>tijuca</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              preset                                             params\n",
       "0          barcelona  {'layers': {'perimeter': {'circle': False}, 's...\n",
       "1  barcelona-plotter  {'layers': {'streets': {'width': {'primary': 5...\n",
       "2            cb-bf-f  {'layers': {'streets': {'width': {'trunk': 6, ...\n",
       "3            default  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "4      heerhugowaard  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "5              macao  {'layers': {'perimeter': {}, 'streets': {'cust...\n",
       "6            minimal  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "7             tijuca  {'layers': {'perimeter': {}, 'streets': {'widt..."
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prettymaps.presets()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To examine a specific preset, run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "|            | layers                                                                                                                                                                                                          | style                                                                                                                                                                                                                                                                         | circle          | radius         |\n",
       "|:-----------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------|:---------------|\n",
       "| perimeter  | {}<br>                                                                                                                                                                                                          | fill: false<br>lw: 0<br>zorder: 0<br>                                                                                                                                                                                                                                         | null<br>...<br> | 500<br>...<br> |\n",
       "| streets    | width:<br>  cycleway: 3.5<br>  footway: 1<br>  motorway: 5<br>  pedestrian: 2<br>  primary: 4.5<br>  residential: 3<br>  secondary: 4<br>  service: 2<br>  tertiary: 3.5<br>  trunk: 5<br>  unclassified: 2<br> | alpha: 1<br>ec: '<span style=\"background-color:#475657; color:#fff\">#475657</span>'<br>fc: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>lw: 0<br>zorder: 4<br>                                                                                      |                 |                |\n",
       "| building   | tags:<br>  building: true<br>  landuse: construction<br>                                                                                                                                                        | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>lw: 0.5<br>palette:<br>- '<span style=\"background-color:#433633; color:#fff\">#433633</span>'<br>- '<span style=\"background-color:#FF5E5B; color:#000\">#FF5E5B</span>'<br>zorder: 5<br>             |                 |                |\n",
       "| water      | tags:<br>  natural:<br>  - water<br>  - bay<br>                                                                                                                                                                 | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#a8e1e6; color:#000\">#a8e1e6</span>'<br>hatch: ooo...<br>hatch_c: '<span style=\"background-color:#9bc3d4; color:#000\">#9bc3d4</span>'<br>lw: 1<br>zorder: 3<br> |                 |                |\n",
       "| forest     | tags:<br>  landuse: forest<br>                                                                                                                                                                                  | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#64B96A; color:#000\">#64B96A</span>'<br>lw: 1<br>zorder: 2<br>                                                                                                  |                 |                |\n",
       "| green      | tags:<br>  landuse:<br>  - grass<br>  - orchard<br>  leisure: park<br>  natural:<br>  - island<br>  - wood<br>                                                                                                  | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#8BB174; color:#000\">#8BB174</span>'<br>hatch: ooo...<br>hatch_c: '<span style=\"background-color:#A7C497; color:#000\">#A7C497</span>'<br>lw: 1<br>zorder: 1<br> |                 |                |\n",
       "| beach      | tags:<br>  natural: beach<br>                                                                                                                                                                                   | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#FCE19C; color:#000\">#FCE19C</span>'<br>hatch: ooo...<br>hatch_c: '<span style=\"background-color:#d4d196; color:#000\">#d4d196</span>'<br>lw: 1<br>zorder: 3<br> |                 |                |\n",
       "| parking    | tags:<br>  amenity: parking<br>  highway: pedestrian<br>  man_made: pier<br>                                                                                                                                    | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#F2F4CB; color:#000\">#F2F4CB</span>'<br>lw: 1<br>zorder: 3<br>                                                                                                  |                 |                |\n",
       "| background | .nan<br>...<br>                                                                                                                                                                                                 | fc: '<span style=\"background-color:#F2F4CB; color:#000\">#F2F4CB</span>'<br>zorder: -1<br>                                                                                                                                                                                     |                 |                |"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "prettymaps.preset('default')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Insted of using the default configuration you can customize several parameters. The most important are:\n",
    "\n",
    "- layers: A dictionary of OpenStreetMap layers to fetch.\n",
    "    - Keys: layer names (arbitrary)\n",
    "    - Values: dicts representing OpenStreetMap queries\n",
    "- style: Matplotlib style parameters\n",
    "    - Keys: layer names (the same as before)\n",
    "    - Values: dicts representing Matplotlib style parameters\n",
    "\n",
    "```python\n",
    "plot = prettymaps.plot(\n",
    "    # Your query. Example: \"Porto Alegre\" or (-30.0324999, -51.2303767) (GPS coords)\n",
    "    your_query,\n",
    "    # Dict of OpenStreetMap Layers to plot. Example:\n",
    "    # {'building': {'tags': {'building': True}}, 'water': {'tags': {'natural': 'water'}}}\n",
    "    # Check the /presets folder for more examples\n",
    "    layers,\n",
    "    # Dict of style parameters for matplotlib. Example:\n",
    "    # {'building': {'palette': ['#f00','#0f0','#00f'], 'edge_color': '#333'}}\n",
    "    style,\n",
    "    # Preset to load. Options include:\n",
    "    # ['default', 'minimal', 'macao', 'tijuca']\n",
    "    preset,\n",
    "    # Save current parameters to a preset file.\n",
    "    # Example: \"my-preset\" will save to \"presets/my-preset.json\"\n",
    "    save_preset,\n",
    "    # Whether to update loaded preset with additional provided parameters. Boolean\n",
    "    update_preset,\n",
    "    # Plot with circular boundary. Boolean\n",
    "    circle,\n",
    "    # Plot area radius. Float\n",
    "    radius,\n",
    "    # Dilate the boundary by this amount. Float\n",
    "    dilate\n",
    ")\n",
    "```\n",
    "\n",
    "**plot** is a python dataclass containing:\n",
    "\n",
    "```python\n",
    "@dataclass\n",
    "class Plot:\n",
    "    # A dictionary of GeoDataFrames (one for each plot layer)\n",
    "    geodataframes: Dict[str, gp.GeoDataFrame]\n",
    "    # A matplotlib figure\n",
    "    fig: matplotlib.figure.Figure\n",
    "    # A matplotlib axis object\n",
    "    ax: matplotlib.axes.Axes\n",
    "```\n",
    "\n",
    "Here's an example of running prettymaps.plot() with customized parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1771376 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    'Praça Ferreira do Amaral, Macau',\n",
    "    circle = True,\n",
    "    radius = 1100,\n",
    "    layers = {\n",
    "        \"green\": {\n",
    "            \"tags\": {\n",
    "                \"landuse\": \"grass\",\n",
    "                \"natural\": [\"island\", \"wood\"],\n",
    "                \"leisure\": \"park\"\n",
    "            }\n",
    "        },\n",
    "        \"forest\": {\n",
    "            \"tags\": {\n",
    "                \"landuse\": \"forest\"\n",
    "            }\n",
    "        },\n",
    "        \"water\": {\n",
    "            \"tags\": {\n",
    "                \"natural\": [\"water\", \"bay\"]\n",
    "            }\n",
    "        },\n",
    "        \"parking\": {\n",
    "            \"tags\": {\n",
    "                \"amenity\": \"parking\",\n",
    "                \"highway\": \"pedestrian\",\n",
    "                \"man_made\": \"pier\"\n",
    "            }\n",
    "        },\n",
    "        \"streets\": {\n",
    "            \"width\": {\n",
    "                \"motorway\": 5,\n",
    "                \"trunk\": 5,\n",
    "                \"primary\": 4.5,\n",
    "                \"secondary\": 4,\n",
    "                \"tertiary\": 3.5,\n",
    "                \"residential\": 3,\n",
    "            }\n",
    "        },\n",
    "        \"building\": {\n",
    "            \"tags\": {\"building\": True},\n",
    "        },\n",
    "    },\n",
    "    style = {\n",
    "        \"background\": {\n",
    "            \"fc\": \"#F2F4CB\",\n",
    "            \"ec\": \"#dadbc1\",\n",
    "            \"hatch\": \"ooo...\",\n",
    "        },\n",
    "        \"perimeter\": {\n",
    "            \"fc\": \"#F2F4CB\",\n",
    "            \"ec\": \"#dadbc1\",\n",
    "            \"lw\": 0,\n",
    "            \"hatch\": \"ooo...\",\n",
    "        },\n",
    "        \"green\": {\n",
    "            \"fc\": \"#D0F1BF\",\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 1,\n",
    "        },\n",
    "        \"forest\": {\n",
    "            \"fc\": \"#64B96A\",\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 1,\n",
    "        },\n",
    "        \"water\": {\n",
    "            \"fc\": \"#a1e3ff\",\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"hatch\": \"ooo...\",\n",
    "            \"hatch_c\": \"#85c9e6\",\n",
    "            \"lw\": 1,\n",
    "        },\n",
    "        \"parking\": {\n",
    "            \"fc\": \"#F2F4CB\",\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 1,\n",
    "        },\n",
    "        \"streets\": {\n",
    "            \"fc\": \"#2F3737\",\n",
    "            \"ec\": \"#475657\",\n",
    "            \"alpha\": 1,\n",
    "            \"lw\": 0,\n",
    "        },\n",
    "        \"building\": {\n",
    "            \"palette\": [\n",
    "                \"#FFC857\",\n",
    "                \"#E9724C\",\n",
    "                \"#C5283D\"\n",
    "            ],\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 0.5,\n",
    "        }\n",
    "    }\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to plot an entire region and not just a rectangular or circular area, set\n",
    "\n",
    "```python\n",
    "radius = False\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 568352 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    'Bom Fim, Porto Alegre, Brasil', radius = False,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can access layers's GeoDataFrames directly like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>addr:housenumber</th>\n",
       "      <th>addr:street</th>\n",
       "      <th>amenity</th>\n",
       "      <th>operator</th>\n",
       "      <th>website</th>\n",
       "      <th>geometry</th>\n",
       "      <th>addr:postcode</th>\n",
       "      <th>name</th>\n",
       "      <th>office</th>\n",
       "      <th>opening_hours</th>\n",
       "      <th>...</th>\n",
       "      <th>contact:phone</th>\n",
       "      <th>bus</th>\n",
       "      <th>public_transport</th>\n",
       "      <th>source:name</th>\n",
       "      <th>government</th>\n",
       "      <th>ways</th>\n",
       "      <th>name:fr</th>\n",
       "      <th>type</th>\n",
       "      <th>building:part</th>\n",
       "      <th>architect</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>element_type</th>\n",
       "      <th>osmid</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>node</th>\n",
       "      <th>2407915698</th>\n",
       "      <td>820</td>\n",
       "      <td>Rua Washington Luiz</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POINT (-51.23212 -30.03670)</td>\n",
       "      <td>90010-460</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">way</th>\n",
       "      <th>126665330</th>\n",
       "      <td>387</td>\n",
       "      <td>Rua dos Andradas</td>\n",
       "      <td>place_of_worship</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POLYGON ((-51.23518 -30.03275, -51.23512 -30.0...</td>\n",
       "      <td>90020-002</td>\n",
       "      <td>Igreja Nossa Senhora das Dores</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126665331</th>\n",
       "      <td>1001</td>\n",
       "      <td>Rua dos Andradas</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>http://www.ruadapraiashopping.com.br</td>\n",
       "      <td>POLYGON ((-51.23167 -30.03066, -51.23160 -30.0...</td>\n",
       "      <td>90020-015</td>\n",
       "      <td>Rua da Praia Shopping</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Mo-Fr 09:00-21:00; Sa 08:00-20:00</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129176990</th>\n",
       "      <td>1020</td>\n",
       "      <td>Rua 7 de Setembro</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>http://www.memorial.rs.gov.br</td>\n",
       "      <td>POLYGON ((-51.23117 -30.02891, -51.23120 -30.0...</td>\n",
       "      <td>90010-191</td>\n",
       "      <td>Memorial do Rio Grande do Sul</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Tu-Sa 10:00-18:00</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129176991</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Praça da Alfândega</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>http://www.margs.rs.gov.br</td>\n",
       "      <td>POLYGON ((-51.23153 -30.02914, -51.23156 -30.0...</td>\n",
       "      <td>90010-150</td>\n",
       "      <td>Museu de Arte do Rio Grande do Sul</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Tu-Su 10:00-19:00</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">relation</th>\n",
       "      <th>6760281</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POLYGON ((-51.23238 -30.03337, -51.23223 -30.0...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[457506887, 457506886]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>multipolygon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6760282</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POLYGON ((-51.23203 -30.03340, -51.23203 -30.0...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Atheneu Espírita Cruzeiro do Sul</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[457506875, 457506889, 457506888]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>multipolygon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6760283</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POLYGON ((-51.23284 -30.03367, -51.23288 -30.0...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Palacete Chaves</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[457506897, 457506896]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>multipolygon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Theodor Wiederspahn</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6760284</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>POLYGON ((-51.23499 -30.03412, -51.23498 -30.0...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[457506910, 457506913]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>multipolygon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14393526</th>\n",
       "      <td>1044</td>\n",
       "      <td>Rua Siqueira Campos</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>https://www.sefaz.rs.gov.br</td>\n",
       "      <td>POLYGON ((-51.23125 -30.02813, -51.23128 -30.0...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Secretaria Estadual da Fazenda</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[236213286, 1081974882]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>multipolygon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2423 rows × 105 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        addr:housenumber          addr:street  \\\n",
       "element_type osmid                                              \n",
       "node         2407915698              820  Rua Washington Luiz   \n",
       "way          126665330               387     Rua dos Andradas   \n",
       "             126665331              1001     Rua dos Andradas   \n",
       "             129176990              1020    Rua 7 de Setembro   \n",
       "             129176991               NaN   Praça da Alfândega   \n",
       "...                                  ...                  ...   \n",
       "relation     6760281                 NaN                  NaN   \n",
       "             6760282                 NaN                  NaN   \n",
       "             6760283                 NaN                  NaN   \n",
       "             6760284                 NaN                  NaN   \n",
       "             14393526               1044  Rua Siqueira Campos   \n",
       "\n",
       "                                  amenity operator  \\\n",
       "element_type osmid                                   \n",
       "node         2407915698               NaN      NaN   \n",
       "way          126665330   place_of_worship      NaN   \n",
       "             126665331                NaN      NaN   \n",
       "             129176990                NaN      NaN   \n",
       "             129176991                NaN      NaN   \n",
       "...                                   ...      ...   \n",
       "relation     6760281                  NaN      NaN   \n",
       "             6760282                  NaN      NaN   \n",
       "             6760283                  NaN      NaN   \n",
       "             6760284                  NaN      NaN   \n",
       "             14393526                 NaN      NaN   \n",
       "\n",
       "                                                      website  \\\n",
       "element_type osmid                                              \n",
       "node         2407915698                                   NaN   \n",
       "way          126665330                                    NaN   \n",
       "             126665331   http://www.ruadapraiashopping.com.br   \n",
       "             129176990          http://www.memorial.rs.gov.br   \n",
       "             129176991             http://www.margs.rs.gov.br   \n",
       "...                                                       ...   \n",
       "relation     6760281                                      NaN   \n",
       "             6760282                                      NaN   \n",
       "             6760283                                      NaN   \n",
       "             6760284                                      NaN   \n",
       "             14393526             https://www.sefaz.rs.gov.br   \n",
       "\n",
       "                                                                  geometry  \\\n",
       "element_type osmid                                                           \n",
       "node         2407915698                        POINT (-51.23212 -30.03670)   \n",
       "way          126665330   POLYGON ((-51.23518 -30.03275, -51.23512 -30.0...   \n",
       "             126665331   POLYGON ((-51.23167 -30.03066, -51.23160 -30.0...   \n",
       "             129176990   POLYGON ((-51.23117 -30.02891, -51.23120 -30.0...   \n",
       "             129176991   POLYGON ((-51.23153 -30.02914, -51.23156 -30.0...   \n",
       "...                                                                    ...   \n",
       "relation     6760281     POLYGON ((-51.23238 -30.03337, -51.23223 -30.0...   \n",
       "             6760282     POLYGON ((-51.23203 -30.03340, -51.23203 -30.0...   \n",
       "             6760283     POLYGON ((-51.23284 -30.03367, -51.23288 -30.0...   \n",
       "             6760284     POLYGON ((-51.23499 -30.03412, -51.23498 -30.0...   \n",
       "             14393526    POLYGON ((-51.23125 -30.02813, -51.23128 -30.0...   \n",
       "\n",
       "                        addr:postcode                                name  \\\n",
       "element_type osmid                                                          \n",
       "node         2407915698     90010-460                                 NaN   \n",
       "way          126665330      90020-002      Igreja Nossa Senhora das Dores   \n",
       "             126665331      90020-015               Rua da Praia Shopping   \n",
       "             129176990      90010-191       Memorial do Rio Grande do Sul   \n",
       "             129176991      90010-150  Museu de Arte do Rio Grande do Sul   \n",
       "...                               ...                                 ...   \n",
       "relation     6760281              NaN                                 NaN   \n",
       "             6760282              NaN    Atheneu Espírita Cruzeiro do Sul   \n",
       "             6760283              NaN                     Palacete Chaves   \n",
       "             6760284              NaN                                 NaN   \n",
       "             14393526             NaN      Secretaria Estadual da Fazenda   \n",
       "\n",
       "                        office                      opening_hours  ...  \\\n",
       "element_type osmid                                                 ...   \n",
       "node         2407915698    NaN                                NaN  ...   \n",
       "way          126665330     NaN                                NaN  ...   \n",
       "             126665331     NaN  Mo-Fr 09:00-21:00; Sa 08:00-20:00  ...   \n",
       "             129176990     NaN                  Tu-Sa 10:00-18:00  ...   \n",
       "             129176991     NaN                  Tu-Su 10:00-19:00  ...   \n",
       "...                        ...                                ...  ...   \n",
       "relation     6760281       NaN                                NaN  ...   \n",
       "             6760282       NaN                                NaN  ...   \n",
       "             6760283       NaN                                NaN  ...   \n",
       "             6760284       NaN                                NaN  ...   \n",
       "             14393526      NaN                                NaN  ...   \n",
       "\n",
       "                        contact:phone  bus public_transport source:name  \\\n",
       "element_type osmid                                                        \n",
       "node         2407915698           NaN  NaN              NaN         NaN   \n",
       "way          126665330            NaN  NaN              NaN         NaN   \n",
       "             126665331            NaN  NaN              NaN         NaN   \n",
       "             129176990            NaN  NaN              NaN         NaN   \n",
       "             129176991            NaN  NaN              NaN         NaN   \n",
       "...                               ...  ...              ...         ...   \n",
       "relation     6760281              NaN  NaN              NaN         NaN   \n",
       "             6760282              NaN  NaN              NaN         NaN   \n",
       "             6760283              NaN  NaN              NaN         NaN   \n",
       "             6760284              NaN  NaN              NaN         NaN   \n",
       "             14393526             NaN  NaN              NaN         NaN   \n",
       "\n",
       "                        government                               ways name:fr  \\\n",
       "element_type osmid                                                              \n",
       "node         2407915698        NaN                                NaN     NaN   \n",
       "way          126665330         NaN                                NaN     NaN   \n",
       "             126665331         NaN                                NaN     NaN   \n",
       "             129176990         NaN                                NaN     NaN   \n",
       "             129176991         NaN                                NaN     NaN   \n",
       "...                            ...                                ...     ...   \n",
       "relation     6760281           NaN             [457506887, 457506886]     NaN   \n",
       "             6760282           NaN  [457506875, 457506889, 457506888]     NaN   \n",
       "             6760283           NaN             [457506897, 457506896]     NaN   \n",
       "             6760284           NaN             [457506910, 457506913]     NaN   \n",
       "             14393526          NaN            [236213286, 1081974882]     NaN   \n",
       "\n",
       "                                 type building:part            architect  \n",
       "element_type osmid                                                        \n",
       "node         2407915698           NaN           NaN                  NaN  \n",
       "way          126665330            NaN           NaN                  NaN  \n",
       "             126665331            NaN           NaN                  NaN  \n",
       "             129176990            NaN           NaN                  NaN  \n",
       "             129176991            NaN           NaN                  NaN  \n",
       "...                               ...           ...                  ...  \n",
       "relation     6760281     multipolygon           NaN                  NaN  \n",
       "             6760282     multipolygon           NaN                  NaN  \n",
       "             6760283     multipolygon           NaN  Theodor Wiederspahn  \n",
       "             6760284     multipolygon           NaN                  NaN  \n",
       "             14393526    multipolygon           NaN                  NaN  \n",
       "\n",
       "[2423 rows x 105 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Run prettymaps in show = False mode (we're only interested in obtaining the GeoDataFrames)\n",
    "plot = prettymaps.plot('Centro Histórico, Porto Alegre', show = False)\n",
    "plot.geodataframes['building']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Search a building by name and display it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"-51.23032682800001 -30.034281028 0.0006073560000103839 0.0008053559999900983\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,-60.067756700000004)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"1.6107119999801965e-05\" opacity=\"0.6\" d=\"M -51.2298412,-30.03353870000001 L -51.2298154,-30.033540599999984 L -51.2298126,-30.0335408 L -51.2298129,-30.033544300000003 L -51.2297808,-30.033546699999988 L -51.2297805,-30.033544400000007 L -51.2297758,-30.0335447 L -51.2297562,-30.0335462 L -51.2297493,-30.033546700000002 L -51.2297572,-30.033626999999992 L -51.22975770000001,-30.033632 L -51.2298302,-30.03362630000001 L -51.2298538,-30.033865000000006 L -51.2298442,-30.0338658 L -51.2298477,-30.033909500000004 L -51.2298412,-30.03390990000001 L -51.2298357,-30.03390249999999 L -51.2298133,-30.033912799999996 L -51.2298168,-30.0339188 L -51.2297959,-30.0339406 L -51.2297906,-30.033938999999993 L -51.2297826,-30.0339586 L -51.2297866,-30.033959199999998 L -51.2297957,-30.034019000000004 L -51.2297902,-30.034021400000004 L -51.229800700000006,-30.0340417 L -51.2298073,-30.0340393 L -51.2298344,-30.034053999999994 L -51.2298319,-30.034065200000004 L -51.2298509,-30.0340704 L -51.2298558,-30.034059600000003 L -51.2298704,-30.0340585 L -51.2298741,-30.034097 L -51.2298921,-30.034095599999993 L -51.2298985,-30.03416019999999 L -51.2298609,-30.034163 L -51.2298683,-30.03423859999999 L -51.2299531,-30.0342322 L -51.2299549,-30.0342512 L -51.2301846,-30.034234 L -51.2301825,-30.0342134 L -51.2302643,-30.03420729999999 L -51.2302569,-30.034132200000002 L -51.2302241,-30.034134599999994 L -51.2302178,-30.0340702 L -51.2302266,-30.0340694 L -51.2302229,-30.034030399999995 L -51.2302285,-30.03403000000001 L -51.230236500000004,-30.0340294 L -51.2302396,-30.034038299999995 L -51.230256600000004,-30.034034099999996 L -51.2302532,-30.0340242 L -51.230280900000004,-30.034001600000003 L -51.2302902,-30.0340033 L -51.23029700000001,-30.033981200000003 L -51.2302871,-30.0339784 L -51.2302841,-30.033920999999996 L -51.2302898,-30.033919600000008 L -51.2302806,-30.0338995 L -51.2302726,-30.033902400000002 L -51.2302486,-30.0338856 L -51.2302511,-30.033877399999994 L -51.2302264,-30.033868700000003 L -51.2302198,-30.033880699999997 L -51.2302148,-30.033878999999995 L -51.230213000000006,-30.033838099999997 L -51.2302054,-30.033838700000004 L -51.2301818,-30.0336 L -51.2302499,-30.033594899999997 L -51.2302471,-30.033566499999996 L -51.2302452,-30.033566699999998 L -51.2302423,-30.0335373 L -51.2302448,-30.033537100000004 L -51.2302419,-30.0335085 L -51.2302051,-30.0335112 L -51.2302053,-30.033513599999992 L -51.2301756,-30.0335159 L -51.2301752,-30.033512399999992 L -51.23014450000001,-30.033514699999994 L -51.2301449,-30.033518200000003 L -51.2300854,-30.033522700000002 L -51.2300843,-30.033511399999984 L -51.2300823,-30.0335115 L -51.2300635,-30.033512799999997 L -51.2300628,-30.033505500000008 L -51.2300334,-30.0335078 L -51.2300336,-30.03350989999999 L -51.2300339,-30.033513 L -51.22995280000001,-30.033519099999996 L -51.229952600000004,-30.033516999999996 L -51.2299524,-30.0335151 L -51.2299225,-30.03351729999999 L -51.2299228,-30.033520499999998 L -51.2298995,-30.03352229999999 L -51.2299009,-30.033537 L -51.2298443,-30.033541300000003 L -51.229844,-30.0335385 L -51.2298412,-30.03353870000001 z\" /></g></svg>",
      "text/plain": [
       "<shapely.geometry.polygon.Polygon at 0x7f0d2d3aa2c0>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot.geodataframes['building'][\n",
    "        plot.geodataframes['building'].name == 'Catedral Metropolitana Nossa Senhora Mãe de Deus'\n",
    "].geometry[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot mosaic of building footprints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 93556 characters]",
      "text/plain": [
       "<Figure size 700x600 with 36 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import osmnx as ox\n",
    "from matplotlib import pyplot as plt\n",
    "from matplotlib.font_manager import FontProperties\n",
    "\n",
    "# Run prettymaps in show = False mode (we're only interested in obtaining the GeoDataFrames)\n",
    "plot = prettymaps.plot('Porto Alegre', show = False)\n",
    "# Get list of buildings from plot's geodataframes dict\n",
    "buildings = plot.geodataframes['building']\n",
    "# Project from lat / long\n",
    "buildings = ox.project_gdf(buildings)\n",
    "buildings = [b for b in buildings.geometry if b.area > 0]\n",
    "\n",
    "# Draw Matplotlib mosaic of n x n building footprints\n",
    "n = 6\n",
    "fig,axes = plt.subplots(n,n, figsize = (7,6))\n",
    "# Set background color\n",
    "fig.patch.set_facecolor('#5cc0eb')\n",
    "# Figure title\n",
    "fig.suptitle(\n",
    "    'Buildings of Porto Alegre',\n",
    "    size = 25,\n",
    "    color = '#fff'\n",
    ")\n",
    "# Draw each building footprint on a separate axis\n",
    "for ax,building in zip(np.concatenate(axes),buildings):\n",
    "    ax.plot(*building.exterior.xy, c = '#ffffff')\n",
    "    ax.autoscale(); ax.axis('off'); ax.axis('equal')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Access plot.ax or plot.fig to add new elements to the matplotlib plot: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1987316 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib.font_manager import FontProperties\n",
    "\n",
    "plot = prettymaps.plot(\n",
    "    (41.39491,2.17557),\n",
    "    preset = 'barcelona',\n",
    ")\n",
    "\n",
    "# Change background color\n",
    "plot.fig.patch.set_facecolor('#F2F4CB')\n",
    "# Add title\n",
    "plot.ax.set_title(\n",
    "    'Barcelona',\n",
    "    size = 50\n",
    ")\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use **plotter** mode to export a pen plotter-compatible SVG (thanks to abey79's amazing [vsketch](https://github.com/abey79/vsketch) library)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 224672 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    (41.39491,2.17557),\n",
    "    mode = 'plotter',\n",
    "    layers = dict(perimeter = {}),\n",
    "    preset = 'barcelona-plotter',\n",
    "    scale_x = .6,\n",
    "    scale_y = -.6,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Some other examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 890432 characters]",
      "text/plain": [
       "<Figure size 2200x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    # City name\n",
    "    'Barra da Tijuca',\n",
    "    dilate = 0,\n",
    "    figsize = (22,10),\n",
    "    preset = 'tijuca',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1969348 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = prettymaps.plot(\n",
    "    'Stad van de Zon, Heerhugowaard, Netherlands',\n",
    "    preset = 'heerhugowaard',\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use prettymaps.create_preset() to create a preset:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "|           | layers                                                                                                                                            | style                                                                                                                                                                                                                                   | circle          | radius          | dilate          |\n",
       "|:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------|:----------------|:----------------|\n",
       "| building  | tags:<br>  building: true<br>  leisure:<br>  - track<br>  - pitch<br>                                                                             | ec: '<span style=\"background-color:#2F3737; color:<span style=\"background-color:#fff; color:#000\">#fff</span>\">#2F3737</span>'<br>lw: 1<br>palette:<br>- '<span style=\"background-color:#fff; color:#000\">#fff</span>'<br>zorder: 4<br> | null<br>...<br> | null<br>...<br> | null<br>...<br> |\n",
       "| streets   | width:<br>  footway: 3<br>  path: 3<br>  pedestrian: 3<br>  primary: 6<br>  residential: 3.5<br>  secondary: 5<br>  tertiary: 4<br>  trunk: 6<br> | ec: '<span style=\"background-color:#2F3737; color:#fff\">#2F3737</span>'<br>fc: '<span style=\"background-color:#F1E6D0; color:#000\">#F1E6D0</span>'<br>lw: 1.5<br>zorder: 3<br>                                                          |                 |                 |                 |\n",
       "| perimeter | .nan<br>...<br>                                                                                                                                   | fill: false<br>lw: 0<br>zorder: 0<br>                                                                                                                                                                                                   |                 |                 |                 |"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "prettymaps.create_preset(\n",
    "    \"my-preset\",\n",
    "    layers = {\n",
    "        \"building\": {\n",
    "            \"tags\": {\n",
    "                \"building\": True,\n",
    "                \"leisure\": [\n",
    "                    \"track\",\n",
    "                    \"pitch\"\n",
    "                ]\n",
    "            }\n",
    "        },\n",
    "        \"streets\": {\n",
    "            \"width\": {\n",
    "                \"trunk\": 6,\n",
    "                \"primary\": 6,\n",
    "                \"secondary\": 5,\n",
    "                \"tertiary\": 4,\n",
    "                \"residential\": 3.5,\n",
    "                \"pedestrian\": 3,\n",
    "                \"footway\": 3,\n",
    "                \"path\": 3\n",
    "            }\n",
    "        },\n",
    "    },\n",
    "    style = {\n",
    "        \"perimeter\": {\n",
    "            \"fill\": False,\n",
    "            \"lw\": 0,\n",
    "            \"zorder\": 0\n",
    "        },\n",
    "        \"streets\": {\n",
    "            \"fc\": \"#F1E6D0\",\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 1.5,\n",
    "            \"zorder\": 3\n",
    "        },\n",
    "        \"building\": {\n",
    "            \"palette\": [\n",
    "                \"#fff\"\n",
    "            ],\n",
    "            \"ec\": \"#2F3737\",\n",
    "            \"lw\": 1,\n",
    "            \"zorder\": 4\n",
    "        }\n",
    "    }\n",
    ")\n",
    "\n",
    "prettymaps.preset('my-preset')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use prettymaps.delete_preset() to delete presets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Before deletion:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>preset</th>\n",
       "      <th>params</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>barcelona</td>\n",
       "      <td>{'layers': {'perimeter': {'circle': False}, 's...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>barcelona-plotter</td>\n",
       "      <td>{'layers': {'streets': {'width': {'primary': 5...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>cb-bf-f</td>\n",
       "      <td>{'layers': {'streets': {'width': {'trunk': 6, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>default</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>heerhugowaard</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>macao</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'cust...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>minimal</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>my-preset</td>\n",
       "      <td>{'layers': {'building': {'tags': {'building': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>tijuca</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              preset                                             params\n",
       "0          barcelona  {'layers': {'perimeter': {'circle': False}, 's...\n",
       "1  barcelona-plotter  {'layers': {'streets': {'width': {'primary': 5...\n",
       "2            cb-bf-f  {'layers': {'streets': {'width': {'trunk': 6, ...\n",
       "3            default  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "4      heerhugowaard  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "5              macao  {'layers': {'perimeter': {}, 'streets': {'cust...\n",
       "6            minimal  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "7          my-preset  {'layers': {'building': {'tags': {'building': ...\n",
       "8             tijuca  {'layers': {'perimeter': {}, 'streets': {'widt..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "After deletion:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>preset</th>\n",
       "      <th>params</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>barcelona</td>\n",
       "      <td>{'layers': {'perimeter': {'circle': False}, 's...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>barcelona-plotter</td>\n",
       "      <td>{'layers': {'streets': {'width': {'primary': 5...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>cb-bf-f</td>\n",
       "      <td>{'layers': {'streets': {'width': {'trunk': 6, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>default</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>heerhugowaard</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>macao</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'cust...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>minimal</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>tijuca</td>\n",
       "      <td>{'layers': {'perimeter': {}, 'streets': {'widt...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              preset                                             params\n",
       "0          barcelona  {'layers': {'perimeter': {'circle': False}, 's...\n",
       "1  barcelona-plotter  {'layers': {'streets': {'width': {'primary': 5...\n",
       "2            cb-bf-f  {'layers': {'streets': {'width': {'trunk': 6, ...\n",
       "3            default  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "4      heerhugowaard  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "5              macao  {'layers': {'perimeter': {}, 'streets': {'cust...\n",
       "6            minimal  {'layers': {'perimeter': {}, 'streets': {'widt...\n",
       "7             tijuca  {'layers': {'perimeter': {}, 'streets': {'widt..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Show presets before deletion\n",
    "print('Before deletion:')\n",
    "display(prettymaps.presets())\n",
    "# Delete 'my-preset'\n",
    "prettymaps.delete_preset('my-preset')\n",
    "# Show presets after deletion\n",
    "print('After deletion:')\n",
    "display(prettymaps.presets())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use **prettymaps.multiplot** and **prettymaps.Subplot** to draw multiple regions on the same canvas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1661104 characters]",
      "text/plain": [
       "<Figure size 1200x1200 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Draw several regions on the same canvas\n",
    "prettymaps.multiplot(\n",
    "    prettymaps.Subplot(\n",
    "        'Cidade Baixa, Porto Alegre',\n",
    "        style={'building': {'palette': ['#49392C', '#E1F2FE', '#98D2EB']}}\n",
    "    ),\n",
    "    prettymaps.Subplot(\n",
    "        'Bom Fim, Porto Alegre',\n",
    "        style={'building': {'palette': ['#BA2D0B', '#D5F2E3', '#73BA9B', '#F79D5C']}}\n",
    "    ),\n",
    "    prettymaps.Subplot(\n",
    "        'Farroupilha, Porto Alegre',\n",
    "        style={'building': {'palette': ['#EEE4E1', '#E7D8C9', '#E6BEAE']}}\n",
    "    ),\n",
    "    # Load a global preset\n",
    "    preset='cb-bf-f',\n",
    "    # Figure size\n",
    "    figsize=(12, 12)\n",
    ")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "main",
   "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.10.6"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "54450f6f75536567d66e0f62469206cde91211157bc4b123d518773c336ee8c7"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
