gpt4 book ai didi

python - Matplotlib 正在打印线图两次/多次

转载 作者:行者123 更新时间:2023-12-01 06:27:10 25 4
gpt4 key购买 nike

如果 Matplotlib 打印线图两次或多次(如下所示),可能会出现什么问题:

enter image description here

这是我的代码:

import pandas as pd
import numpy as np
import scipy
import matplotlib.pyplot as plt
from scipy import integrate


def compute_integrated_spectral_response_ikonos(file, sheet):
df = pd.read_excel(file, sheet_name=sheet, header=2)

blue = integrate.cumtrapz(df['Blue'], df['Wavelength'])
green = integrate.cumtrapz(df['Green'], df['Wavelength'])
red = integrate.cumtrapz(df['Red'], df['Wavelength'])
nir = integrate.cumtrapz(df['NIR'], df['Wavelength'])
pan = integrate.cumtrapz(df['Pan'], df['Wavelength'])


plt.figure(num=None, figsize=(6, 4), dpi=80, facecolor='w', edgecolor='k')
plt.plot(df[1:], blue, label='Blue', color='darkblue');
plt.plot(df[1:], green, label='Green', color='b');
plt.plot(df[1:], red, label='Red', color='g');
plt.plot(df[1:], nir, label='NIR', color='r');
plt.plot(df[1:], pan, label='Pan', color='darkred')
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Spectral Response (%)')
plt.title(f'Integrated Spectral Response of {sheet} Bands')
plt.show()

compute_integrated_spectral_response_ikonos('Sorted Wavelengths.xlsx', 'IKONOS')

这是我的 dataset .

最佳答案

这是因为绘制 df[1:] 是将整个数据帧绘制为 x 轴。

>>> df[1:]
Wavelength Blue Green Red NIR Pan
1 355 0.001463 0.000800 0.000504 0.000532 0.000619
2 360 0.000866 0.000729 0.000391 0.000674 0.000361
3 365 0.000731 0.000806 0.000597 0.000847 0.000244
4 370 0.000717 0.000577 0.000328 0.000729 0.000435
5 375 0.001251 0.000842 0.000847 0.000906 0.000914
.. ... ... ... ... ... ...
133 1015 0.002601 0.002100 0.001752 0.002007 0.149330
134 1020 0.001602 0.002040 0.002341 0.001793 0.136372
135 1025 0.001946 0.002218 0.001260 0.002754 0.118682
136 1030 0.002417 0.001376 0.000898 0.000000 0.103634
137 1035 0.001300 0.001602 0.000000 0.000000 0.089097

[137 rows x 6 columns]

切片[1:]仅给出没有第一行的数据帧。将 df[1:] 的每个实例更改为 df['Wavelength'][1:] 给出了我认为的预期输出:

>>> df['Wavelength'][1:]
1 355
2 360
3 365
4 370
5 375

133 1015
134 1020
135 1025
136 1030
137 1035
Name: Wavelength, Length: 137, dtype: int64

输出:

enter image description here

关于python - Matplotlib 正在打印线图两次/多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60079986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com