hw1: ex5 works (wip)
This commit is contained in:
parent
6e9bc0f9de
commit
971062f9a8
1 changed files with 52 additions and 21 deletions
|
@ -1803,8 +1803,8 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 127,
|
||||
"id": "f3c0739b",
|
||||
"execution_count": 128,
|
||||
"id": "75225ed4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -2009,7 +2009,7 @@
|
|||
"[5 rows x 49 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 127,
|
||||
"execution_count": 128,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -2028,7 +2028,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 126,
|
||||
"execution_count": 166,
|
||||
"id": "11612845",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -2036,11 +2036,11 @@
|
|||
"data": {
|
||||
"application/vnd.bokehjs_exec.v0+json": "",
|
||||
"text/html": [
|
||||
"<script id=\"p2994\">\n",
|
||||
"<script id=\"p7925\">\n",
|
||||
" (function() {\n",
|
||||
" const xhr = new XMLHttpRequest()\n",
|
||||
" xhr.responseType = 'blob';\n",
|
||||
" xhr.open('GET', \"http://localhost:50568/autoload.js?bokeh-autoload-element=p2994&bokeh-absolute-url=http://localhost:50568&resources=none\", true);\n",
|
||||
" xhr.open('GET', \"http://localhost:50851/autoload.js?bokeh-autoload-element=p7925&bokeh-absolute-url=http://localhost:50851&resources=none\", true);\n",
|
||||
" xhr.onload = function (event) {\n",
|
||||
" const script = document.createElement('script');\n",
|
||||
" const src = URL.createObjectURL(event.target.response);\n",
|
||||
|
@ -2054,7 +2054,7 @@
|
|||
},
|
||||
"metadata": {
|
||||
"application/vnd.bokehjs_exec.v0+json": {
|
||||
"server_id": "41ac9a694474477fa4aff5c18022d7c8"
|
||||
"server_id": "de3272d393da49aba1d3fd3516574d15"
|
||||
}
|
||||
},
|
||||
"output_type": "display_data"
|
||||
|
@ -2063,11 +2063,25 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"aaaaaaa\n",
|
||||
"aaaaaaa\n",
|
||||
"aaaaaaa\n",
|
||||
"aaaaaaa\n",
|
||||
"aaaaaaa\n"
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n",
|
||||
"Index(['NAME', 'geometry', 'routes'], dtype='object')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -2080,6 +2094,7 @@
|
|||
"from bokeh.models.ranges import Range1d\n",
|
||||
"from bokeh.palettes import Reds\n",
|
||||
"from bokeh.models import LinearColorMapper, LogColorMapper, ColorBar\n",
|
||||
"from shapely import Point\n",
|
||||
"\n",
|
||||
"yurop_json = yurop.to_json()\n",
|
||||
"\n",
|
||||
|
@ -2102,28 +2117,44 @@
|
|||
" tools = \"pan, wheel_zoom, box_zoom, reset\")\n",
|
||||
"\n",
|
||||
" geo_ds = GeoJSONDataSource(geojson=yurop_json)\n",
|
||||
" \n",
|
||||
" plotted_districts = p.patches('xs','ys', source = geo_ds,\n",
|
||||
" line_color = 'black', \n",
|
||||
" line_width = 0.25)\n",
|
||||
"\n",
|
||||
" p.xgrid.grid_line_color = None\n",
|
||||
" p.ygrid.grid_line_color = None\n",
|
||||
" p.axis.visible = False\n",
|
||||
"\n",
|
||||
" p.patches(\"xs\",\"ys\", source = geo_ds,\n",
|
||||
" fill_color = {\"field\" : \"TotaleAbitantiCurr\",\n",
|
||||
" fill_color = {\"field\" : \"routes\",\n",
|
||||
" \"transform\" : color_mapper},\n",
|
||||
" line_color = \"gray\", \n",
|
||||
" line_width = 0.25, \n",
|
||||
" fill_alpha = 1)\n",
|
||||
" \n",
|
||||
" p.xgrid.grid_line_color = None\n",
|
||||
" p.ygrid.grid_line_color = None\n",
|
||||
" p.axis.visible = False\n",
|
||||
" \n",
|
||||
" p.add_tools(HoverTool(renderers = [plotted_districts],\n",
|
||||
" tooltips = [(\"Country\",\"@NAME\")]))\n",
|
||||
" tooltips = [(\"Country\",\"@NAME\"),(\"# routes\",\"@routes\")]))\n",
|
||||
"\n",
|
||||
" def event():\n",
|
||||
" print(\"aaaaaaa\")\n",
|
||||
" tool = TapTool()\n",
|
||||
" \n",
|
||||
" tap = p.add_tools(TapTool())\n",
|
||||
" def event(x):\n",
|
||||
" # Figure out the country that intersects the coordinates we clicked\n",
|
||||
" intersects = yurop[yurop.intersects(Point(x.x, x.y))]\n",
|
||||
" if len(intersects) == 0:\n",
|
||||
" return\n",
|
||||
" \n",
|
||||
" routes_from_country = intersects.iloc[0, 2:].to_frame(name='routes')\n",
|
||||
" gdf_country_flights = yurop.set_index('NAME').loc[:, ['geometry']] \\\n",
|
||||
" .join(routes_from_country) \\\n",
|
||||
" .reset_index()\n",
|
||||
" print(gdf_country_flights.columns)\n",
|
||||
" \n",
|
||||
" geo_ds_country = gdf_country_flights.to_json()\n",
|
||||
" \n",
|
||||
" geo_ds.geojson = geo_ds_country\n",
|
||||
"\n",
|
||||
" tap = p.add_tools()\n",
|
||||
" p.on_event(Tap, event)\n",
|
||||
" \n",
|
||||
" p.add_layout(color_bar, \"right\")\n",
|
||||
|
|
Reference in a new issue