Matplotlib печатает линейный сюжет дважды / несколько раз - PullRequest
1 голос
/ 05 февраля 2020

В чем может быть проблема, если 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')

Вот мой набор данных .

1 Ответ

1 голос
/ 05 февраля 2020

Это связано с тем, что при построении графика 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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...