python 绘制双y轴,将折线加粗并在折线上做标记

之前的笔记折线实在是太细了,并且还有点透明,放在论文中特别难看,现在修改一下折线,并且绘制双y轴

 

#!usr/bin/env python
# -*- coding:utf-8 _*-
"""

@author:Suyue
@file:zhexian.py
@time:2024/04/$
{DAY}
@desc:
"""
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
matplotlib.rc("font",family='YouYuan')

input_file = 'D:/z9457area.xlsx'

df = pd.read_excel(input_file)
x = df['时间']
y1 = df['回波强度均值']
y2 = df['20dBz面积']
y3 = df['30dBz面积']
y4 = df['40dBz面积']



fig, ax1 = plt.subplots()
ax1.set_xlabel('时间',fontsize=15)
ax1.set_ylabel('回波面积',fontsize=15)
lin2 = ax1.plot(x,y2,ls="-",alpha=2, linewidth=3, label='abc',color='green')
lin3 =ax1.plot(x,y3,ls="-",alpha=2, linewidth=3, label='abc',color='yellow')
lin4 =ax1.plot(x,y4,ls="-",alpha=2, linewidth=3, label='abc',color='orange')
plt.tick_params(labelsize=16)

ax2 = ax1.twinx()
ax2.set_ylabel('回波强度均值',fontsize=15)
lin1 = ax2.plot(x,y1,ls="--",alpha=0.5, linewidth=3, label='abc',color='black')

plt.tick_params(labelsize=16)
plt.title('20240715加格达奇',fontsize=15)
# 合并图例
lines = lin1+lin2+lin3+lin4
labs = ['回波强度均值','20dBz面积','30dBz面积','40dBz面积']
plt.legend(lines,labs,loc='center left',fontsize=15)



# 加飞机作业开始结束标记
x_axis_data = df['时间']
start_time = df.at[3,'时间'] #时间那列对应的飞机作业开始时间的行数
end_time = df.at[20,'时间']
plt.scatter(start_time,0,color='red',s=50)
plt.scatter(end_time,0,color='red',s=50)
plt.show()

 

posted @ 2024-08-30 23:22  秋刀鱼CCC  Views(26)  Comments(0Edit  收藏  举报