Python 如何将图例添加到choropleth地图中?

Python 如何将图例添加到choropleth地图中?,python,legend,choropleth,Python,Legend,Choropleth,我想在我的choropleth地图上添加一个图例。我已经使用geoplotlib库进行了绘图,但是,我在互联网上找不到关于这个库的太多信息。因此,我不可能找到一种方法来显示图例,根据颜色梯度显示最大值和最小值。你知道我怎么做吗 import geoplotlib from geoplotlib.colors import ColorMap from geoplotlib.utils import BoundingBox import json #Define function get_col

我想在我的choropleth地图上添加一个图例。我已经使用geoplotlib库进行了绘图,但是,我在互联网上找不到关于这个库的太多信息。因此,我不可能找到一种方法来显示图例,根据颜色梯度显示最大值和最小值。你知道我怎么做吗

import geoplotlib
from geoplotlib.colors import ColorMap
from geoplotlib.utils import BoundingBox
import json


#Define function get_color, returns the colour in which each county has to bee painted according to the number of TCAS RA (stored in pos variable) and the color map chosen (stored in the cmap variable).
def get_color(properties):
    key = str(int(properties['STATE'])) + properties['COUNTY']
    if key in pos5:
        return cmap.to_color(pos5.get(key), 2, 'lin')
    else:
        return [0, 0, 0, 0]

#Open and load pos2.json file.
with open ('C:\\Users\\W7\\PycharmProjects\\Test\\pos5.json') as fin:
    pos5 = json.load(fin)

#Select a color map
cmap = geoplotlib.colors.ColorMap('Reds', alpha=255, levels=10)

#We draw the polygons that size counties, painting them according to get_color
geoplotlib.geojson('C:\\Users\\W7\\PycharmProjects\\Test\\gz_2010_us_050_00_20m.json',
                   fill=True,
                   color=get_color,
                   f_tooltip=lambda properties: properties['NAME'])

#We paint the borders of each polygon in black
geoplotlib.geojson('C:\\Users\\W7\\PycharmProjects\\Test\\gz_2010_us_050_00_20m.json',
                   fill=False,
                   color=[0, 0, 0, 64])

#Open and read the file containing the airports in which VJ has experienced a TCAS RA.
data=geoplotlib.utils.read_csv("C:\\Users\\W7\\PycharmProjects\\Test\\seven.csv")

#Print points to the map
geoplotlib.dot(data,color='r',point_size=1.8)

#Print name of the airports
geoplotlib.labels(data,'name',color=[255,0,0,255],font_size=12,anchor_x='center')

#Focus on USA Visualization
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.USA)

#Show the map
geoplotlib.show()

多谢各位

我建议与本期的作者联系()。有人问他这个功能。有一个ColorBar类,但没有关于如何使用它的文档。我建议与该问题的作者联系()。有人问他这个功能。有一个ColorBar类,但没有如何使用它的文档。