pysal.viz.splot.mapping.
vba_choropleth
(x, y, gdf, cmap='GnBu', divergent=False, revert_alpha=False, alpha_mapclassify=None, rgb_mapclassify=None, ax=None, legend=False)[源代码]¶alpha choropleth值
参数: |
|
---|---|
返回: |
|
实例
进口
>>> from pysal.lib import examples
>>> import geopandas as gpd
>>> import matplotlib.pyplot as plt
>>> import matplotlib
>>> import numpy as np
>>> from pysal.viz.splot.mapping import vba_choropleth
加载示例数据
>>> link_to_data = examples.get_path('columbus.shp')
>>> gdf = gpd.read_file(link_to_data)
>>> x = gdf['HOVAL'].values
>>> y = gdf['CRIME'].values
用alpha映射绘制值
>>> fig, _ = vba_choropleth(x, y, gdf)
>>> plt.show()
使用还原的alpha值按alpha映射绘制值
>>> fig, _ = vba_choropleth(x, y, gdf, cmap='RdBu',
... revert_alpha=True)
>>> plt.show()
使用分类的alpha和rgb值按alpha映射绘制值
>>> fig, axs = plt.subplots(2,2, figsize=(20,10))
>>> vba_choropleth(y, x, gdf, cmap='viridis', ax = axs[0,0],
... rgb_mapclassify=dict(classifier='quantiles', k=3),
... alpha_mapclassify=dict(classifier='quantiles', k=3))
>>> vba_choropleth(y, x, gdf, cmap='viridis', ax = axs[0,1],
... rgb_mapclassify=dict(classifier='natural_breaks'),
... alpha_mapclassify=dict(classifier='natural_breaks'))
>>> vba_choropleth(y, x, gdf, cmap='viridis', ax = axs[1,0],
... rgb_mapclassify=dict(classifier='std_mean'),
... alpha_mapclassify=dict(classifier='std_mean'))
>>> vba_choropleth(y, x, gdf, cmap='viridis', ax = axs[1,1],
... rgb_mapclassify=dict(classifier='fisher_jenks', k=3),
... alpha_mapclassify=dict(classifier='fisher_jenks', k=3))
>>> plt.show()
传递颜色列表而不是CMAP
>>> color_list = ['#a1dab4','#41b6c4','#225ea8']
>>> vba_choropleth(y, x, gdf, cmap=color_list,
... rgb_mapclassify=dict(classifier='quantiles', k=3),
... alpha_mapclassify=dict(classifier='quantiles'))
>>> plt.show()
添加图例并使用发散的alpha值
>>> fig = plt.figure(figsize=(15,10))
>>> ax = fig.add_subplot(111)
>>> vba_choropleth(x, y, gdf, divergent=True,
... alpha_mapclassify=dict(classifier='quantiles', k=5),
... rgb_mapclassify=dict(classifier='quantiles', k=5),
... legend=True, ax=ax)
>>> plt.show()
( Source code )