【跟着SCI学作图】Matplotlib fill_between的简单应用

【跟着SCI学作图】Matplotlib fill_between的简单应用

01 引言:

今天接着复现【Future increases in Arctic lightning and fire risk for permafrost carbon】的图表,主要是Matplotlib的fill_between和fill_betweenx的简单应用。
在这里插入图片描述
论文中提供的数据如下图所示:
请添加图片描述

数据下载地址:
【https://www.nature.com/articles/s41558-021-01011-y#Sec17】

02 代码如下:

# -*- 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 结果如下:

请添加图片描述

以上就是本期推文的全部内容了,如果对你有帮助的话,请‘点赞’、‘收藏’,‘关注’,你们的支持是我更新的动力。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值