- 积分
- 2429
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2021-10-27
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
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)
|
-
|