0
我想在图中感兴趣的点注释并绘制一条线。我已经为它写了一个代码,它完成了这项工作。在图中注释兴趣点(Matplotlib)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fsource=('/Users/Maxwell/Desktop/OES data.xlsx')
df=pd.read_excel(fsource,header = 1, parse_cols = "C:D",names=['Wavelength','Intensity'])
fig1 = plt.figure()
f, ax = plt.subplots(1, figsize = (8,4))
ax.set_xlabel('Wavelength',fontsize=15)
ax.set_ylabel('Intensity',fontsize=15)
ax.plot(df['Wavelength'],df['Intensity'],color='red')
ax.set_xlim(xmin=400,xmax=800)
ax.set_ylim(ymin=0,ymax=5000) #Specify the max and min of y axis
ax.tick_params(axis= 'both', labelsize=12) #fontsize of x & y ticks as 12
ax.axvline(x= 604,color='black',ymin=0.05, ymax=0.5) #x=604 is my point of interest.
ax.annotate('POF-1', xy=(604, 2400),fontsize=12)
plt.show()
我有一个关于这个方法/步骤一些问题:?
有没有做同样的工作更有效率/更好的办法(任何改进的代码等)
我的代码仅适用于一个兴趣点'POF-1'。如果我有几个兴趣点,我将不得不一一给它们编号,并且一次又一次地指定行的长度。我应该怎么做才能使任务自动化,使注释和线条同时出现在所有兴趣点?(例如,用一些预定义文本注释点x = 500,730,790等)。
的链接,原始文件是OES数据在link