我看了一下 geopandas 绘图函数的代码(
https://github.com/geopandas/geopandas/blob/master/geopandas/plotting.py),但我想
plot
方法只接受三个名称之一("quantiles", "equal_interval", "fisher_jenks"),而不是直接接受一个 bins 列表或者像
User_Defined
这样的
pysal.esda.mapclassify
分类器。(我猜这可能与该
问题有关,最后一条评论是关于定义“用户定义”分 binning 的 API。)
然而,目前来看,您可以通过轻微修改并重用我链接的文件中的函数来实现这一点。
例如,你可以像这样重新编写你自己的版本
plot_dataframe
:
import numpy as np
def plot_dataframe(s, column, binning, cmap,
linewidth=1.0, figsize=None, **color_kwds):
import matplotlib.pyplot as plt
values = s[column]
values = np.array(binning.yb)
fig, ax = plt.subplots(figsize=figsize)
ax.set_aspect('equal')
mn = values.min()
mx = values.max()
poly_idx = np.array(
(s.geometry.type == 'Polygon') | (s.geometry.type == 'MultiPolygon'))
polys = s.geometry[poly_idx]
if not polys.empty:
plot_polygon_collection(ax, polys, values[poly_idx], True,
vmin=mn, vmax=mx, cmap=cmap,
linewidth=linewidth, **color_kwds)
plt.draw()
return ax
接下来,您需要定义函数_flatten_multi_geoms和plot_polygon_collection,通过复制它们并准备好像这样使用:
bins = [5, 20, 100, 600, 1000, 3000, 5000, 10000, 20000, 400000]
ud = User_Defined(projected_world_exports['Value'], bins)
plot_dataframe(projected_world_exports, 'Value', ud, 'Greens')