use*_*562 1 python-2.7 bokeh datashader
最初,我创建了英国邮政编码区域的交互式地图,其中单个区域根据其值(例如该邮政编码区域中的人口)用颜色表示,如下所示。
from bokeh.plotting import figure
from bokeh.palettes import Viridis256 as palette
from bokeh.models import LinearColorMapper
from bokeh.models import ColumnDataSource
import geopandas as gpd
shp = 'file_path_to_the_downloaded_shapefile'
#read shape file into dataframe using geopandas
df = gpd.read_file(shp)
def expandMultiPolygons(row, geometry):
if row[geometry].type = 'MultiPolygon':
row[geometry] = [p for p in row[geometry]]
return row
#Some rows were in MultiPolygons instead of Polygons.
#Expand MultiPolygons to multi rows of Polygons
df = df.apply(expandMultiPolygons, geometry='geometry', axis=1)
df = df.set_index('Area')['geometry'].apply(pd.Series).stack().reset_index()
#Visualize the polygons. To visualize different colors for different post areas, I added another column called 'value' which has some random integer value.
p = figure()
color_mapper = LinearColorMapper(palette=palette)
source = ColumnDataSource(df)
p.patches('x', 'y', source=source,\
fill_color={'field': 'value', 'transform': color_mapper},\
fill_alpha=1.0, line_color="black", line_width=0.05)
Run Code Online (Sandbox Code Playgroud)
其中df是四列的数据框:邮政编码区域,x坐标,y坐标,值(即总体)。
上面的代码在网络浏览器上创建了一个交互式地图,这很棒,但是我注意到交互性在速度上不是很平稳。如果放大或移动地图,它会缓慢渲染。数据帧的大小只有1106行,所以我很困惑为什么它这么慢。
作为一种可能的解决方案,我遇到了datashader(https://datashader.readthedocs.io/en/latest/),但是我发现示例脚本相当复杂,并且大多数脚本都在Jupyter笔记本上带有holoview包,但我想要使用bokeh创建仪表板。
有人建议我将数据着色器合并到上述bokeh脚本中吗?我是否需要在datashader中使用其他函数来创建形状图,而不是使用bokeh的patch函数?
任何建议将不胜感激!!!
没有数据文件,我无法直接回答您的问题,但是可以提供一些观察结果:
| 归档时间: |
|
| 查看次数: |
1325 次 |
| 最近记录: |