我期望得到绿、黄、红三种颜色的图例,
即使底部范围为空(没有低于 10 的数字)。
相反,GeoPandas 会放弃黄色并使用绿色两次。
这是一个错误还是我错过了一个参数?
import pandas as pd
import geopandas
from matplotlib.colors import ListedColormap
colors = ['green', 'yellow', 'red']
bins = [10, 30]
numbers = [15, 25, 35, 35, 55]
ny = geopandas.read_file(geopandas.datasets.get_path('nybb'))
numbers = pd.Series(numbers, name='numbers')
ny = pd.concat([ny, numbers], axis=1)
ny.plot(
legend=True,
column='numbers',
scheme="user_defined",
cmap = ListedColormap(colors),
classification_kwds={'bins': bins},
)
我能够通过设置来解决这个问题norm
范围:
import pandas as pd
import geopandas
from matplotlib.colors import ListedColormap
from matplotlib.colors import Normalize
colors = ['green', 'yellow', 'red']
bins = [10, 30]
numbers = [15, 25, 35, 35, 55]
ny = geopandas.read_file(geopandas.datasets.get_path('nybb'))
numbers = pd.Series(numbers, name='numbers')
ny = pd.concat([ny, numbers], axis=1)
ny.plot(
legend=True,
column='numbers',
scheme="user_defined",
cmap=ListedColormap(colors),
classification_kwds={ 'bins': bins, },
norm=Normalize(0, len(colors)),
)
我不完全知道我在这里做什么。基本上,我认为我阻止了将颜色范围标准化为缩小的数字范围的默认行为。这是理解源代码和简单的试验和错误的结合。至少它可以满足我的需求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)