之前的筆記折線實在是太細了,並且還有點透明,放在論文中特別難看,現在修改一下折線,並且繪製雙y軸
#!usr/bin/env python # -*- coding:utf-8 _*- """ @author:Suyue @file:jakjdklj.py @time:2024/08/30 {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:/z9470area.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('時間') ax1.set_ylabel('回波面積') 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') ax2 = ax1.twinx() ax2.set_ylabel('回波強度均值') lin1 = ax2.plot(x,y1,ls="--",alpha=0.5, linewidth=3, label='abc',color='black') plt.title('20240715海拉爾') # 合併圖例 lines = lin1+lin2+lin3+lin4 labs = ['回波強度均值','20dBz面積','30dBz面積','40dBz面積'] plt.legend(lines,labs,loc='right') # 加飛機作業開始結束標記 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()