亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Matplotlib 正在打印線圖兩次/多次

Matplotlib 正在打印線圖兩次/多次

jeck貓 2022-07-19 10:37:12
如果 Matplotlib 像這樣打印線圖兩次或多次,可能會出現什么問題:這是我的代碼:import pandas as pdimport numpy as npimport scipyimport matplotlib.pyplot as pltfrom 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 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

這是因為繪圖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:]只給出沒有第一行的數據框。改變 to 的每個實例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

輸出:

http://img1.sycdn.imooc.com//62d6190000016c4e05310312.jpg

查看完整回答
反對 回復 2022-07-19
  • 1 回答
  • 0 關注
  • 85 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號