增加地图标签的字体大小

问题描述 投票:0回答:1

我下面的代码创建一个shapefile的映射:

import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt

pm10_base = gpd.read_file('/Users/jacob/Desktop/MSthesis/wrfpy/actual/mmshp/population_by_lgu.shp')






# set the value column that will be visualised
variable = 'NAME_2'

# create figure and axes for Matplotlib
fig, ax = plt.subplots(1, figsize=(8, 10))
# remove the axis
ax.axis('off')
# add a title and annotation
ax.set_title('Metro Manila LGU Division ', fontdict={'fontsize': '20', 'fontweight' : '4'})

# create map
pm10_base.plot(column='NAME_2', alpha= 0.9, linewidth=0.02, ax=ax, edgecolor='0.8')


# Add Labels
pm10_base['coords'] = pm10_base['geometry'].apply(lambda x: x.representative_point().coords[:])
pm10_base['coords'] = [coords[0] for coords in pm10_base['coords']]
for idx, row in pm10_base.iterrows():
    plt.annotate(s=row['NAME_2'], xy=row['coords'],horizontalalignment='center', )



plt.savefig('/Users/jacob/Desktop/figure312.png', bbox_inches = 'tight', pad_inches = 0)

其他都可以;但是,我想扩大城市的名称。

如何从下面的代码输出中看到,增加城市名称的字体大小?

任何人将不胜感激。

谢谢!

enter image description here

python-3.x matplotlib geopandas
1个回答
0
投票

我没玩太多,但是size没有.annotate参数吗?

类似这样的东西:

plt.annotate(s=row['NAME_2'], xy=row['coords'], horizontalalignment='center', size=99, )

© www.soinside.com 2019 - 2024. All rights reserved.