Interactive geoplots in dashboard layout with Bokeh¶
Written by Chan Kimsan, 2022
Objective¶
Create interactive geoplots of drought index in dashboard layout using Bokeh.
Environment¶
Install via pip
pip install pandas-bokeh
Install via conda:
conda install -c patrikhlobil pandas-bokeh
For detail of Installation and How To Use, you can follow the instructions on Pandas-Bokeh 0.5.5 documentation.
Code¶
[1]:
# Import geo module
import geopandas as gpd
import pandas as pd
[2]:
# Import bokeh module and load it
import pandas_bokeh
pandas_bokeh.output_notebook()
[3]:
# input filepath
fp = 'data/Srepok_Basin.shp'
# read data
dataframe = gpd.read_file(fp)
# check the head row in dataframe
dataframe.head()
[3]:
| OBJECTID | GRIDCODE | Subbasin | Area | Slo1 | Len1 | Sll | Csl | Wid1 | Dep1 | ... | Shape_Area | HydroID | OutletID | 3Junec | 3AugC | 3NovC | 6Junec | 6AugC | 6NovC | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 55 | 55 | 55 | 28870.83 | 4.578035 | 4874.665581 | 91.435538 | 0.205142 | 38.624714 | 1.253508 | ... | 288708300.0 | 300055 | 100056 | -1.108180 | -1.10818 | -0.892015 | -1.108180 | -1.39446 | -1.39446 | POLYGON ((703549.617 1492389.931, 703549.617 1... |
| 1 | 56 | 56 | 56 | 24414.21 | 5.557022 | 6916.980515 | 60.957025 | 0.289144 | 34.928128 | 1.172197 | ... | 244142100.0 | 300056 | 100058 | -0.404028 | -1.10818 | 0.000000 | -0.404028 | -1.10818 | -1.10818 | POLYGON ((717319.617 1490679.931, 717319.617 1... |
| 2 | 57 | 57 | 57 | 24486.30 | 3.511215 | 22726.967517 | 91.435538 | 0.013200 | 34.989973 | 1.173580 | ... | 244863000.0 | 300057 | 100057 | -1.108180 | -1.89135 | -0.892015 | -1.108180 | -1.89135 | -1.39446 | MULTIPOLYGON (((718039.617 1496439.931, 718129... |
| 3 | 58 | 58 | 58 | 38749.59 | 6.978042 | 14922.230509 | 60.957025 | 0.187640 | 46.083980 | 1.410101 | ... | 387495900.0 | 300058 | 100062 | -0.551064 | -1.39446 | -0.551064 | -0.551064 | -1.39446 | -1.89135 | POLYGON ((808759.617 1486629.931, 808759.617 1... |
| 4 | 59 | 59 | 59 | 42588.18 | 6.231790 | 25090.678554 | 60.957025 | 0.175364 | 48.771168 | 1.464398 | ... | 425881800.0 | 300059 | 100063 | -0.551064 | -1.39446 | -0.551064 | -0.551064 | -1.39446 | -1.89135 | POLYGON ((812719.617 1481499.931, 812629.617 1... |
5 rows × 27 columns
[4]:
# Create individual plot
# Plot of drought index on 3JuneC column
plot_3Junec = dataframe.plot_bokeh(
category="3Junec",
colormap="Reds",
legend="Drought Index",
show_figure=False)
# Plot of drought index on 3AugC column
plot_3AugC = dataframe.plot_bokeh(
category="3AugC",
colormap="Reds",
legend="Drought Index",
show_figure=False)
# Plot of drought index on 3NovC column
plot_3NovC = dataframe.plot_bokeh(
category="3NovC",
colormap="Reds",
legend="Drought Index",
show_figure=False)
# Plot of drought index on 6Junec column
plot_6Junec = dataframe.plot_bokeh(
category="6Junec",
colormap="Reds",
legend="Drought Index",
show_figure=False)
# Plot of drought index on 6AugC column
plot_6AugC = dataframe.plot_bokeh(
category="6AugC",
colormap="Reds",
legend="Drought Index",
show_figure=False)
# Plot of drought index on 6NovC column
plot_6NovC = dataframe.plot_bokeh(
category="6NovC",
colormap="Reds",
legend="Drought Index",
show_figure=False)
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
C:\Users\a9418\AppData\Roaming\Python\Python37\site-packages\pyproj\crs\crs.py:68: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))
[5]:
# Make Dashboard with Grid Layout:
pandas_bokeh.plot_grid([[plot_3Junec, plot_6Junec],
[plot_3AugC, plot_6AugC],
[plot_3NovC, plot_6NovC]], width=450)
[5]:
Column(
id = '1498', …)