我正在使用Geopandas在美国Map上绘制计数。我想将绘图/图形的背景更改为黑色,但我无法在Geopandas中定位设置。
我猜我需要使用matplotlib。我筛选了这个文档,但我没有看到任何与背景相关的内容。我做错了什么?
这是我的代码:
import geopandas as gpd
us_map = gpd.read_file('tl_2020_us_state.shp')
names = ['Alaska', 'Hawaii', 'United States Virgin Islands', 'Commonwealth of the Northern Mariana Islands', 'Guam', 'American Samoa', 'Puerto Rico']
updated_us_map = us_map.loc[~(us_map)['NAME'].isin(names)]
state_occurrences = us_only_places_df['State'].value_counts().reset_index().rename(columns={'index':'NAME','State':'count'})
merge_map = updated_us_map.merge(state_occurrences, on='NAME')
merge_map.plot(column='count', cmap='Oranges', legend=True, legend_kwds={'label': "Number of Places", 'orientation': "vertical", 'shrink':0.4}, figsize=(15,20), edgecolor='black', set_facecolor = '#F0F0F0')
plt.title('Count of Places Saved for each US States')
根据建议更新代码:
import geopandas as gpd
us_map = gpd.read_file('tl_2020_us_state.shp')
names = ['Alaska', 'Hawaii', 'United States Virgin Islands', 'Commonwealth of the Northern Mariana Islands', 'Guam', 'American Samoa', 'Puerto Rico']
updated_us_map = us_map.loc[~(us_map)['NAME'].isin(names)]
state_occurrences = us_only_places_df['State'].value_counts().reset_index().rename(columns={'index':'NAME','State':'count'})
merge_map = updated_us_map.merge(state_occurrences, on='NAME')
fig, ax = plt.subplots(figsize=(2,2))
merge_map.plot(column='count', cmap='Oranges', legend=True, legend_kwds={'label': "Number of Places", 'orientation': "vertical", 'shrink':0.4}, figsize=(5,5), edgecolor='black')
plt.title('Count of Places Saved for each US States')
1条答案
按热度按时间nlejzf6q1#
正如您提到的,您可以使用matplotlib及其模块pyplot(
import matplotlib.pyplot as plt
)和subplots
函数。你可以试试这样的方法:
让我知道这是否有效,您可以使用
alpha=0.4
中的输入参数更改透明度