Ниже мой пример кода:
Код: Выделить всё
data = {
'country': ['United States', 'China', 'India', 'Brazil', 'Australia'],
'(LU (PDF)': [0.00000001, 0.0000001, 0.0000005, 0.000001, 0.00001]
}
fabio_country = pd.DataFrame(data)
# Load the world map data
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# Merge the world map with your DataFrame
world = world.merge(fabio_country, left_on='name', right_on='country', how='left')
# Define your bins
bins = [0, 0.000000001, 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001]
labels = ['0', '0.000000001', '0.00000001', '0.0000001', '0.000001', '0.00001', '0.0001', '0.001']
# Classify the data
world['binned'] = pd.cut(world['LU (PDF)'], bins=bins, labels=labels, include_lowest=True)
# Convert to Robinson projection
world = world.to_crs('ESRI:54030')
# Plotting
fig, ax = plt.subplots(1, 1, figsize=(15, 10))
world.boundary.plot(ax=ax)
cmap = plt.get_cmap('OrRd', len(labels))
norm = Normalize(vmin=0, vmax=len(labels)-1)
world.plot(column='binned', ax=ax, legend=False, cmap=cmap, norm=norm, edgecolor='black')
# Create a horizontal legend
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([])
cbar = plt.colorbar(sm, orientation='horizontal', fraction=0.046, pad=0.04)
cbar.set_ticks(range(len(labels)))
cbar.set_ticklabels(labels)
cbar.set_label('PDF')
plt.title('Biodiversity loss caused by land use in PDF')
plt.show()

Подробнее здесь: https://stackoverflow.com/questions/787 ... matplotlib