01 引言:
数据下载地址:
【https://www.nature.com/articles/s41558-021-01011-y#Sec17】
02 代码如下:
# -*- encoding: utf-8 -*-
# -*- encoding: utf-8 -*-
'''
@File : png3.py
@Time : 2022/12/28 13:19:42
@Author : HMX
@Version : 1.0
@Contact : kzdhb8023@163.com
'''
# here put the import lib
import os
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
os.chdir(r'E:\CODE\work\plot7\png3\data')
data = '41558_2021_1011_MOESM4_ESM.csv'
df = pd.read_csv(data,index_col=0)
df.dis = df.dis*-1
print(df)
fig,ax = plt.subplots(figsize = (6,3),dpi = 100)
lns1 = ax.plot(df.dis,df.FR_HIST,color = 'r',label = 'Present day (1986–2005)')
ax.fill_between(df.dis,df.FR_HIST-df.FRstd_HIST,df.FR_HIST+df.FRstd_HIST,alpha = 0.2,color = 'r')
lns2 = ax.plot(df.dis,df.FR_FT,label = 'Future (2081–2100)',linestyle = ':')
ax.fill_between(df.dis,df.FR_FT-df.FRstd_FT,df.FR_FT+df.FRstd_FT,alpha = 0.2)
ax.set_ylim(0,1)
ax.set_xlim(-800,500)
ax2 = ax.twinx()
lns3 = ax2.plot(df.dis,df.dFR,color = 'purple',label ='Change')
ax2.set_ylim(0,250)
ax2.set_yticks(np.arange(0,241,80))
ax2.fill_betweenx([0,250],[0,0],[500,500],color = 'tab:orange',alpha = 0.2,zorder = 0)
lns = lns1+lns2+lns3
labs = [l.get_label() for l in lns]
ax.legend(lns, labs,loc = 'upper left',frameon=False)
ax.set_ylabel('Lightning flash rate'+'\n'+'(number per km$^{2}$ per month)')
ax2.set_ylabel('Flash rate change (%)',color = 'purple',rotation = 270,labelpad = 20)
ax.set_xlabel('Distance north of treeline (km)')
plt.tight_layout()
plt.savefig('png3.png',dpi = 600)
plt.show()
03 结果如下:
戳这里关注我
请点赞、在看、关注,你们的支持是我更新的动力。