|
29 | 29 | "from holoviews.selection import link_selections\n", |
30 | 30 | "from holoviews.operation import gridmatrix\n", |
31 | 31 | "from holoviews.operation.element import histogram\n", |
32 | | - "from holoviews import opts" |
| 32 | + "from holoviews import opts\n", |
| 33 | + "\n", |
| 34 | + "import warnings\n", |
| 35 | + "warnings.simplefilter(\"ignore\")" |
33 | 36 | ] |
34 | 37 | }, |
35 | 38 | { |
|
67 | 70 | "outputs": [], |
68 | 71 | "source": [ |
69 | 72 | "gdf.loc[:, 'x'], gdf.loc[:, 'y'] = lnglat_to_meters(gdf.geometry.x, gdf.geometry.y)\n", |
70 | | - "df = pd.DataFrame(gdf)" |
| 73 | + "df = pd.DataFrame(gdf).head(10000)" |
71 | 74 | ] |
72 | 75 | }, |
73 | 76 | { |
|
106 | 109 | "source": [ |
107 | 110 | "def selected_bar_plot(x_range, y_range):\n", |
108 | 111 | " if x_range:\n", |
109 | | - " tmp = df[(df.x>x_range[0])&(df.x<x_range[1])]\n", |
| 112 | + " tmp = df[(df.x > x_range[0]) & (df.x < x_range[1]) & (df.y > y_range[0]) & (df.y < y_range[1])]\n", |
110 | 113 | " else:\n", |
111 | 114 | " tmp = df\n", |
112 | | - " return tmp.groupby(\"ShipType\").count().hvplot.bar(x=\"ShipType\", y='MMSI', width=400, rot=90)\n", |
| 115 | + " counts = tmp.groupby(\"ShipType\").count()\n", |
| 116 | + " counts = counts.reset_index()\n", |
| 117 | + " n_all = counts.MMSI.sum()\n", |
| 118 | + " n_max = counts.MMSI.max()\n", |
| 119 | + " return counts.hvplot.bar(title=f\"{n_max} records\", x=\"ShipType\", y='MMSI', width=400, height=400, rot=90, color=\"ShipType\", colormap=\"Category20\", ylim=(0,n_max),)\n", |
113 | 120 | "\n", |
114 | | - "map_plot = df.hvplot.scatter(x='x', y='y', c=\"ShipType\", width=700, height=300)\n", |
| 121 | + "map_plot = df.hvplot.scatter(title=f\"AIS\", x='x', y='y', c=\"ShipType\", width=700, height=400, colormap=\"Category20\")\n", |
115 | 122 | "rangexy = hv.streams.RangeXY(source=map_plot)\n", |
116 | 123 | " \n", |
| 124 | + "map_plot + hv.DynamicMap(selected_bar_plot, streams=[rangexy])" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "code", |
| 129 | + "execution_count": null, |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
117 | 133 | "map_plot << hv.DynamicMap(selected_bar_plot, streams=[rangexy])" |
118 | 134 | ] |
119 | 135 | }, |
| 136 | + { |
| 137 | + "cell_type": "code", |
| 138 | + "execution_count": null, |
| 139 | + "metadata": {}, |
| 140 | + "outputs": [], |
| 141 | + "source": [ |
| 142 | + "map_plot + hv.DynamicMap(selected_bar_plot, streams=[rangexy])" |
| 143 | + ] |
| 144 | + }, |
120 | 145 | { |
121 | 146 | "cell_type": "markdown", |
122 | 147 | "metadata": {}, |
|
0 commit comments