{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import bqplot.pyplot as plt\n", "from bqplot import Orthographic, ColorScale, Mercator, AlbersUSA, Tooltip" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Map ##" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='Basic Map')\n", "plt.geo(map_data='WorldMap')\n", "fig" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Advanced Map and Projection ##" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='Advanced Map')\n", "geo_scale = Orthographic(scale_factor=375, center=[0, 25], rotate=(-50, 0))\n", "plt.scales(scales={'projection': geo_scale})\n", "map_mark = plt.geo(map_data='WorldMap', \n", " colors={682: 'Green', 356: 'Red', 643: '#0000ff', 'default_color': 'DarkOrange'})\n", "fig" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geo_scale.scale = 350" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Choropleth ##" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='Choropleth')\n", "plt.scales(scales={'projection': Mercator(), 'color': ColorScale(scheme='YlOrRd')})\n", "chloro_map = plt.geo(map_data='WorldMap', \n", " color={643: 105., 4: 21., 398: 23., 156: 42., 124:78., 76: 98.},\n", " colors={'default_color': 'Grey'})\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## USA State Map ##" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='US States Map')\n", "plt.scales(scales={'projection': AlbersUSA()})\n", "states_map = plt.geo(map_data='USStatesMap')\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Europe Country Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='Europe Countries Map')\n", "plt.scales(scales={'projection': Mercator(scale_factor=450)})\n", "euro_map = plt.geo(map_data='EuropeMap')\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactions ##" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(title='Interactions')\n", "def_tt = Tooltip(fields=['id', 'name'])\n", "map_mark = plt.geo(map_data='WorldMap', tooltip=def_tt, \n", " interactions={'click': 'select', 'hover': 'tooltip'})\n", "fig" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# clicking on any country will update the 'selected' attribute of map_mark\n", "map_mark.selected" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6" } }, "nbformat": 4, "nbformat_minor": 1 }