cf3 = ax3.scatter(lon_eu1,lat_eu1,s=50
, marker = 'o',c = number_eu,cmap='viridis_r'
,transform=ccrs.PlateCarree(),vmin=0,vmax=9,
)
plt.text(-48,45,"(c)",fontdict={'size':'20','color':'k'},backgroundcolor = 'w')
# cb1 = fig.colorbar(cf1, orientation='vertical',ticks = np.arange(0, 10, 1),
# fraction=0.07, pad = 0.03)
colorbar = fig.add_axes([0.1, 0.05, 0.8, 0.03])
cbar1 = fig.colorbar(cf1,ticks = [0,1,2,3,4,5,6,7,8,9],cax = colorbar,orientation='horizontal',
format='%d',extendrect=True, drawedges=False)
cbar1.ax.tick_params(labelsize=12)
这里重点是c = number_eu这个参数,它代表每一个点的大小并投影到cmap色标上,而lon_eu1、lat_eu1两个对于不想画的点在之前一步赋值为0即可,如下所示:
lon_eu1 = lon_eu1.T
for i in range(lon_eu.shape[0]):
for j in range(lat_eu.shape[0]):
if n3[i,j] == 0:
lon_eu1[i,j] = 0
lat_eu1[i,j] = 0
#这里我是将n3=0的位置赋值为0,就是不把它画在图上
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rcParams
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
# plt.rcParams['font.serif']=['Times New Roman']
# plt.rcParams['font.sans-serif'] = ['SimSun'] #'SimSun'是宋体
# plt.yticks(fontfamily='Times New Roman')
font1={'family':'Times New Roman','weight':'bold','size':10}
#设置全局中文宋体,英文为Times New Roman
config = {
"font.family": 'serif',
"font.size": 11.5,# 相当于小四大小
"mathtext.fontset": 'stix',#matplotlib渲染数学字体时使用的字体,和Times New Roman差别不大
"font.serif": ['SimSun'],#宋体
'axes.unicode_minus': False # 处理负号,即-号
}
rcParams.update(config)
# 创建字典
ins_name = ['4800-5000hPa','5000-5200hPa','5200-5400hPa','5400-5600hPa','5600-5800hPa']
mon_name = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
result1 = dict(zip(ins_name,mon_per1))
fig=plt.figure(figsize=(7,8))
ax1=plt.subplot(111)
width = 0.4
bottom1 = np.zeros(12)
bottom2 = np.zeros(12)
bottom3 = np.zeros(12)
#因为我要画五种强度的柱状图并且强度递进,所以我将色标“hot”分成5份投影到category_colors1
category_colors1 = plt.colormaps['hot'](
np.linspace(0.15, 0.85, 5))
# =============================================================================
# picture1
# =============================================================================
kk=0
for boolean, weight_count in result1.items():
p1 = ax1.bar(mon_name, weight_count, width, label=boolean, bottom=bottom1,color = category_colors1[kk])
bottom1 += weight_count
kk+=1
plt.yticks(range(0,17,2))
#标注每一个柱形代表的数值大小
for nn in range(12):
sum_data = sum(mon_per1[:,nn])
plt.text(nn-0.35,sum_data+0.65,str(round(sum_data,2))+'%',fontdict = font1,va='center',ha='left')
#设置标签
plt.text(-0.7,13.8,"(a)",fontdict={'size':'15','color':'k'})
#做图注bbox_to_anchor控制图的位置大小,ncol对应图注个数,这里为5
ax1.legend(ncol=len(ins_name), bbox_to_anchor=(-0.08, 1.05),
loc='lower left', fontsize=8)