Debian Codegraph @

bqplot/examples/Marks/Pyplot/Map.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import bqplot.pyplot as plt\n",
10 "from bqplot import Orthographic, ColorScale, Mercator, AlbersUSA, Tooltip"
11 ]
12 },
13 {
14 "cell_type": "markdown",
15 "metadata": {},
16 "source": [
17 "## Basic Map ##"
18 ]
19 },
20 {
21 "cell_type": "code",
22 "execution_count": null,
23 "metadata": {},
24 "outputs": [],
25 "source": [
26 "fig = plt.figure(title='Basic Map')\n",
27 "plt.geo(map_data='WorldMap')\n",
28 "fig"
29 ]
30 },
31 {
32 "cell_type": "markdown",
33 "metadata": {
34 "collapsed": true
35 },
36 "source": [
37 "## Advanced Map and Projection ##"
38 ]
39 },
40 {
41 "cell_type": "code",
42 "execution_count": null,
43 "metadata": {},
44 "outputs": [],
45 "source": [
46 "fig = plt.figure(title='Advanced Map')\n",
47 "geo_scale = Orthographic(scale_factor=375, center=[0, 25], rotate=(-50, 0))\n",
48 "plt.scales(scales={'projection': geo_scale})\n",
49 "map_mark = plt.geo(map_data='WorldMap', \n",
50 " colors={682: 'Green', 356: 'Red', 643: '#0000ff', 'default_color': 'DarkOrange'})\n",
51 "fig"
52 ]
53 },
54 {
55 "cell_type": "code",
56 "execution_count": null,
57 "metadata": {},
58 "outputs": [],
59 "source": [
60 "geo_scale.scale = 350"
61 ]
62 },
63 {
64 "cell_type": "markdown",
65 "metadata": {},
66 "source": [
67 "## Choropleth ##"
68 ]
69 },
70 {
71 "cell_type": "code",
72 "execution_count": null,
73 "metadata": {},
74 "outputs": [],
75 "source": [
76 "fig = plt.figure(title='Choropleth')\n",
77 "plt.scales(scales={'projection': Mercator(), 'color': ColorScale(scheme='YlOrRd')})\n",
78 "chloro_map = plt.geo(map_data='WorldMap', \n",
79 " color={643: 105., 4: 21., 398: 23., 156: 42., 124:78., 76: 98.},\n",
80 " colors={'default_color': 'Grey'})\n",
81 "fig"
82 ]
83 },
84 {
85 "cell_type": "markdown",
86 "metadata": {},
87 "source": [
88 "## USA State Map ##"
89 ]
90 },
91 {
92 "cell_type": "code",
93 "execution_count": null,
94 "metadata": {},
95 "outputs": [],
96 "source": [
97 "fig = plt.figure(title='US States Map')\n",
98 "plt.scales(scales={'projection': AlbersUSA()})\n",
99 "states_map = plt.geo(map_data='USStatesMap')\n",
100 "fig"
101 ]
102 },
103 {
104 "cell_type": "markdown",
105 "metadata": {},
106 "source": [
107 "## Europe Country Map"
108 ]
109 },
110 {
111 "cell_type": "code",
112 "execution_count": null,
113 "metadata": {},
114 "outputs": [],
115 "source": [
116 "fig = plt.figure(title='Europe Countries Map')\n",
117 "plt.scales(scales={'projection': Mercator(scale_factor=450)})\n",
118 "euro_map = plt.geo(map_data='EuropeMap')\n",
119 "fig"
120 ]
121 },
122 {
123 "cell_type": "markdown",
124 "metadata": {},
125 "source": [
126 "## Interactions ##"
127 ]
128 },
129 {
130 "cell_type": "code",
131 "execution_count": null,
132 "metadata": {},
133 "outputs": [],
134 "source": [
135 "fig = plt.figure(title='Interactions')\n",
136 "def_tt = Tooltip(fields=['id', 'name'])\n",
137 "map_mark = plt.geo(map_data='WorldMap', tooltip=def_tt, \n",
138 " interactions={'click': 'select', 'hover': 'tooltip'})\n",
139 "fig"
140 ]
141 },
142 {
143 "cell_type": "code",
144 "execution_count": null,
145 "metadata": {},
146 "outputs": [],
147 "source": [
148 "# clicking on any country will update the 'selected' attribute of map_mark\n",
149 "map_mark.selected"
150 ]
151 }
152 ],
153 "metadata": {
154 "kernelspec": {
155 "display_name": "Python 3",
156 "language": "python",
157 "name": "python3"
158 },
159 "language_info": {
160 "codemirror_mode": {
161 "name": "ipython",
162 "version": 3
163 },
164 "file_extension": ".py",
165 "mimetype": "text/x-python",
166 "name": "python",
167 "nbconvert_exporter": "python",
168 "pygments_lexer": "ipython3",
169 "version": "3.7.6"
170 }
171 },
172 "nbformat": 4,
173 "nbformat_minor": 1
174 }