Skip to content

Commit b7df9c5

Browse files
committed
make activity03 more efficient
1 parent ab66fd7 commit b7df9c5

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

lesson07/Activity03/activity03_solution.ipynb

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
{
2929
"cell_type": "code",
30-
"execution_count": 3,
30+
"execution_count": 1,
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"cell_type": "code",
50-
"execution_count": 4,
50+
"execution_count": 2,
5151
"metadata": {},
5252
"outputs": [
5353
{
@@ -78,7 +78,7 @@
7878
},
7979
{
8080
"cell_type": "code",
81-
"execution_count": 5,
81+
"execution_count": 3,
8282
"metadata": {},
8383
"outputs": [
8484
{
@@ -325,7 +325,7 @@
325325
"[5 rows x 96 columns]"
326326
]
327327
},
328-
"execution_count": 5,
328+
"execution_count": 3,
329329
"metadata": {},
330330
"output_type": "execute_result"
331331
}
@@ -379,7 +379,7 @@
379379
},
380380
{
381381
"cell_type": "code",
382-
"execution_count": 6,
382+
"execution_count": 4,
383383
"metadata": {},
384384
"outputs": [],
385385
"source": [
@@ -413,7 +413,7 @@
413413
},
414414
{
415415
"cell_type": "code",
416-
"execution_count": 7,
416+
"execution_count": 5,
417417
"metadata": {},
418418
"outputs": [],
419419
"source": [
@@ -428,7 +428,7 @@
428428
},
429429
{
430430
"cell_type": "code",
431-
"execution_count": 8,
431+
"execution_count": 6,
432432
"metadata": {},
433433
"outputs": [],
434434
"source": [
@@ -457,7 +457,7 @@
457457
},
458458
{
459459
"cell_type": "code",
460-
"execution_count": 9,
460+
"execution_count": 7,
461461
"metadata": {},
462462
"outputs": [
463463
{
@@ -588,7 +588,7 @@
588588
},
589589
{
590590
"cell_type": "code",
591-
"execution_count": 10,
591+
"execution_count": 8,
592592
"metadata": {},
593593
"outputs": [],
594594
"source": [
@@ -599,7 +599,7 @@
599599
},
600600
{
601601
"cell_type": "code",
602-
"execution_count": 11,
602+
"execution_count": 9,
603603
"metadata": {},
604604
"outputs": [
605605
{
@@ -684,7 +684,7 @@
684684
"4 21644 40.828028 -73.947308 89.0 100.0"
685685
]
686686
},
687-
"execution_count": 11,
687+
"execution_count": 9,
688688
"metadata": {},
689689
"output_type": "execute_result"
690690
}
@@ -725,7 +725,7 @@
725725
},
726726
{
727727
"cell_type": "code",
728-
"execution_count": 12,
728+
"execution_count": 10,
729729
"metadata": {},
730730
"outputs": [],
731731
"source": [
@@ -736,7 +736,7 @@
736736
},
737737
{
738738
"cell_type": "code",
739-
"execution_count": 13,
739+
"execution_count": 43,
740740
"metadata": {},
741741
"outputs": [],
742742
"source": [
@@ -804,7 +804,7 @@
804804
},
805805
{
806806
"cell_type": "code",
807-
"execution_count": 15,
807+
"execution_count": 20,
808808
"metadata": {},
809809
"outputs": [],
810810
"source": [
@@ -832,12 +832,14 @@
832832
" max_val = max(self.data[self.display])\n",
833833
" scale = 'log' if self.display == 'dollar_price' else 'lin'\n",
834834
" \n",
835-
" for id in self.data['id']:\n",
836-
" grp = self.data.where(self.data['id'] == id)\n",
837-
" color = self.cmap.to_color(max(grp[self.display], 1), max_val, scale)\n",
838-
" self.painter.set_color(color)\n",
835+
" for index, id in enumerate(self.data['id']):\n",
836+
" # log scale can't start at 0, must be 1\n",
837+
" min_val = max(self.data[self.display][index], 1)\n",
839838
" \n",
840-
" x, y = proj.lonlat_to_screen(grp['lon'], grp['lat'])\n",
839+
" color = self.cmap.to_color(min_val, max_val, scale)\n",
840+
" self.painter.set_color(color)\n",
841+
" lat, lon = self.data['lon'][index], self.data['lat'][index]\n",
842+
" x, y = proj.lonlat_to_screen(lat, lon)\n",
841843
" self.painter.points(x, y, 5)\n",
842844
" \n",
843845
" def draw(self, proj, mouse_x, mouse_y, ui_manager):\n",
@@ -869,7 +871,7 @@
869871
},
870872
{
871873
"cell_type": "code",
872-
"execution_count": 16,
874+
"execution_count": 21,
873875
"metadata": {},
874876
"outputs": [],
875877
"source": [
@@ -881,7 +883,7 @@
881883
},
882884
{
883885
"cell_type": "code",
884-
"execution_count": 17,
886+
"execution_count": 22,
885887
"metadata": {},
886888
"outputs": [],
887889
"source": [
@@ -890,6 +892,13 @@
890892
"geoplotlib.add_layer(ValueLayer(data, bbox=ny_bbox))\n",
891893
"geoplotlib.show()"
892894
]
895+
},
896+
{
897+
"cell_type": "code",
898+
"execution_count": null,
899+
"metadata": {},
900+
"outputs": [],
901+
"source": []
893902
}
894903
],
895904
"metadata": {

0 commit comments

Comments
 (0)