Skip to content

Commit 872ca9a

Browse files
committed
Added Highcharts Maps for Python demos.
1 parent bed2b28 commit 872ca9a

File tree

8 files changed

+1607
-91
lines changed

8 files changed

+1607
-91
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b61ab4e2-55d4-4159-96c0-b5ab12954d59",
6+
"metadata": {},
7+
"source": [
8+
"# Heatmap Demo\n",
9+
"This demo depicts a (literal) heatmap, showing the temperature variation by day and hour throughout the month of May 2017."
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"id": "36247b6d-8b86-4c54-9142-b47d3f994eca",
15+
"metadata": {
16+
"tags": []
17+
},
18+
"source": [
19+
"## Import Dependencies"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"id": "03fde0d1-880a-467a-9aac-777ebf7c59f3",
26+
"metadata": {
27+
"tags": []
28+
},
29+
"outputs": [],
30+
"source": [
31+
"from highcharts_maps import constants\n",
32+
"from highcharts_maps.chart import Chart\n",
33+
"from highcharts_maps.options.series.heatmap import HeatmapSeries\n",
34+
"import pandas\n",
35+
"import datetime"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"id": "e0000636-b68e-488e-b15f-988ebc1d8b6a",
41+
"metadata": {},
42+
"source": [
43+
"## Prepare the Configuration"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"id": "0a5ab4ab-0e15-4cbc-a2fb-83bf97e48d3f",
50+
"metadata": {
51+
"tags": []
52+
},
53+
"outputs": [],
54+
"source": [
55+
"options_kwargs = {\n",
56+
" 'chart': {\n",
57+
" 'type': 'heatmap',\n",
58+
" 'inverted': True\n",
59+
" },\n",
60+
"\n",
61+
" 'accessibility': {\n",
62+
" 'description': 'We see how temperatures are warmer during the day, especially from around 9am to 9pm. May 8th through 11th are also overall colder days compared to the rest. Overall the temperatures range from around -1 degrees C to around 23 degrees C.'\n",
63+
" },\n",
64+
"\n",
65+
" 'title': {\n",
66+
" 'text': 'Highcharts Heat Map',\n",
67+
" 'align': 'left'\n",
68+
" },\n",
69+
"\n",
70+
" 'subtitle': {\n",
71+
" 'text': 'Temperature variation by day and hour through May 2017',\n",
72+
" 'align': 'left'\n",
73+
" },\n",
74+
"\n",
75+
" 'xAxis': {\n",
76+
" 'tickPixelInterval': 50,\n",
77+
" 'min': datetime.date(2017, 5, 1),\n",
78+
" 'max': datetime.date(2017, 5, 31),\n",
79+
" 'labels': {\n",
80+
" 'enabled': True,\n",
81+
" 'format': '{value:%Y-%m-%d}'\n",
82+
" }\n",
83+
" },\n",
84+
"\n",
85+
" 'yAxis': {\n",
86+
" 'accessibility': {\n",
87+
" 'description': 'Hours in the day'\n",
88+
" },\n",
89+
" 'title': {\n",
90+
" 'text': constants.EnforcedNull\n",
91+
" },\n",
92+
" 'labels': {\n",
93+
" 'format': '{value}:00'\n",
94+
" },\n",
95+
" 'minPadding': 0,\n",
96+
" 'maxPadding': 0,\n",
97+
" 'startOnTick': False,\n",
98+
" 'endOnTick': False,\n",
99+
" 'tickPositions': [0, 6, 12, 18, 24],\n",
100+
" 'tickWidth': 1,\n",
101+
" 'min': 0,\n",
102+
" 'max': 23\n",
103+
" },\n",
104+
"\n",
105+
" 'colorAxis': {\n",
106+
" 'stops': [\n",
107+
" [0, '#3060cf'],\n",
108+
" [0.5, '#fffbbc'],\n",
109+
" [0.9, '#c4463a']\n",
110+
" ],\n",
111+
" 'min': -5\n",
112+
" }\n",
113+
"}"
114+
]
115+
},
116+
{
117+
"cell_type": "markdown",
118+
"id": "83ea7d23-2026-4a15-9144-e30001406eb8",
119+
"metadata": {},
120+
"source": [
121+
"## Populate the Dataframe"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": null,
127+
"id": "a51b0171-0852-4f72-94a5-af08626144a6",
128+
"metadata": {
129+
"tags": []
130+
},
131+
"outputs": [],
132+
"source": [
133+
"df = pandas.read_csv('temperatures.csv')\n",
134+
"df"
135+
]
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"id": "2294327c-46ec-425d-8f4e-0e618607c037",
140+
"metadata": {},
141+
"source": [
142+
"## Create the Series"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": null,
148+
"id": "8fb6490d-cb69-4ed3-995b-8df7389caee3",
149+
"metadata": {
150+
"tags": []
151+
},
152+
"outputs": [],
153+
"source": [
154+
"series = HeatmapSeries.from_pandas(df, \n",
155+
" property_map = {'x': 'Date','y': 'Time', 'value': 'Temperature'}, \n",
156+
" series_kwargs = {\n",
157+
" 'name': 'Temperature',\n",
158+
" 'borderWidth': 0,\n",
159+
" 'colsize': 24 * 36e5,\n",
160+
" 'tooltip': {\n",
161+
" 'headerFormat': 'Temperature<br/>',\n",
162+
" 'pointFormat': '{point.x:%e %b, %Y} {point.y}:00: <b>{point.value} ℃</b>'\n",
163+
" },\n",
164+
" 'accessibility': {\n",
165+
" 'enabled': False\n",
166+
" }\n",
167+
" })"
168+
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"id": "22f593cd-1641-46db-aca3-4aaeec8d59bb",
173+
"metadata": {},
174+
"source": [
175+
"## Assemble the Chart"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "d54eeb90-3535-4973-b44e-8109bf480c4e",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"chart = Chart(options = options_kwargs)\n",
186+
"chart.is_maps_chart = True\n",
187+
"chart.add_series(series)"
188+
]
189+
},
190+
{
191+
"cell_type": "markdown",
192+
"id": "da99cefc-d953-4764-8392-a704e34702a8",
193+
"metadata": {},
194+
"source": [
195+
"## Display the Chart"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"id": "97eb8175-132f-48ac-bfeb-58d10dae40a6",
202+
"metadata": {},
203+
"outputs": [],
204+
"source": [
205+
"chart.display()"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"id": "4f9e0f1e-4fef-4538-bf71-366ab6484d3e",
212+
"metadata": {},
213+
"outputs": [],
214+
"source": []
215+
}
216+
],
217+
"metadata": {
218+
"kernelspec": {
219+
"display_name": "Python 3 (ipykernel)",
220+
"language": "python",
221+
"name": "python3"
222+
},
223+
"language_info": {
224+
"codemirror_mode": {
225+
"name": "ipython",
226+
"version": 3
227+
},
228+
"file_extension": ".py",
229+
"mimetype": "text/x-python",
230+
"name": "python",
231+
"nbconvert_exporter": "python",
232+
"pygments_lexer": "ipython3",
233+
"version": "3.10.5"
234+
}
235+
},
236+
"nbformat": 4,
237+
"nbformat_minor": 5
238+
}

0 commit comments

Comments
 (0)