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

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

如何從多個文件繪制最小-最大填充之間圖

如何從多個文件繪制最小-最大填充之間圖

隔江千里 2023-09-26 14:22:09
預先感謝您的幫助?。ㄏ旅娴拇a)(鏈接到第一個數據)(鏈接到我要添加的數據)我正在嘗試從第二個 CSV(上圖)導入數據,并根據該 CSV 數據向該圖添加第二行。執行此操作的最佳方法是什么?(下圖)圖上的波浪線代表數據的范圍。import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport warningswarnings.filterwarnings('ignore')raw_data = pd.read_csv('all-deep-soil-temperatures.csv', index_col=1, parse_dates=True)df_all_stations = raw_data.copy()selected_soil_station = 'Minot'df_selected_station = df_all_stations[df_all_stations['Station'] == selected_soil_station]df_selected_station.fillna(method = 'ffill', inplace=True);df_selected_station_D=df_selected_station.resample(rule='D').mean()df_selected_station_D['Day'] = df_selected_station_D.index.dayofyearmean=df_selected_station_D.groupby(by='Day').mean()mean['Day']=mean.indexmaxx=df_selected_station_D.groupby(by='Day').max()minn=df_selected_station_D.groupby(by='Day').min()mean['maxx20']=maxx['20 cm']mean['minn20']=minn['20 cm']plt.style.use('ggplot')bx = mean.plot(x='Day', y='20 cm',color='black')plt.fill_between(mean['Day'],mean['minn20'],mean['maxx20'],color='blue',alpha = 0.2);bx.set_xlabel("Day of the year")bx.set_ylabel("Temperature in Celsius")bx.set_title("Soil Temp, Air Temp, and Snow Depth for " + str(selected_soil_station))我擁有的:我想要擁有什么:
查看完整描述

1 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

  • 查看新代碼的內聯符號

  • 刪除是plt.style.use('ggplot')因為很難看到fill_between顏色

  • 不要;在 python 中使用

  • 將其他文件中的數據加載到單獨的數據框中

  • 根據需要清理并聚合新數據

    • 將日期列設置為日期時間格式

    • 提取一年中的某一天

    • groupby一年中的某一天和總計mean,?min, 和max溫度

  • 將新數據繪制為axes與原始圖相同的圖,bx。

df_all_stations = pd.read_csv('data/so_data/2020-09-29 64128817/all-deep-soil-temperatures.csv', index_col=1, parse_dates=True)


# load air temp data

at = pd.read_csv('data/so_data/2020-09-29 64128817/allStationsDailyAirTemp1.csv')


# set Date to a datetime format

at.Date = pd.to_datetime(at.Date)


# extract day of year

at['doy'] = at.Date.dt.dayofyear


# selet data from Minot

at = at[at.Station == 'Minot']


# groupby the day of year (doy) and aggregate min max and mean

atg = at.groupby('doy')['Temp'].agg([min, max, 'mean'])


selected_soil_station = 'Minot'

df_selected_station = df_all_stations[df_all_stations['Station'] == selected_soil_station].copy()? # make a copy here, otherwise there will be warning

df_selected_station.fillna(method = 'ffill', inplace=True)

df_selected_station_D=df_selected_station.resample(rule='D').mean()

df_selected_station_D['Day'] = df_selected_station_D.index.dayofyear

mean=df_selected_station_D.groupby(by='Day').mean()

mean['Day']=mean.index


maxx=df_selected_station_D.groupby(by='Day').max()

minn=df_selected_station_D.groupby(by='Day').min()

mean['maxx20']=maxx['20 cm']

mean['minn20']=minn['20 cm']


bx = mean.plot(x='Day', y='20 cm', color='black', figsize=(9, 6), label='20 cm Soil Temp')

plt.fill_between(mean['Day'], mean['minn20'], mean['maxx20'], color='blue', alpha = 0.2, label='20 cm Soil Temp Range')


# add air temp plot to the bx plot with ax=bx

atg['mean'].plot(ax=bx, label='Mean Air Temp')


# add air temp fill between plot to the bx plot

bx.fill_between(atg.index, atg['min'], atg['max'], color='cyan', alpha = 0.2, label='Air Temp Range')


bx.set_xlabel("Day of the year")

bx.set_ylabel("Temperature in Celsius")

bx.set_title("Soil Temp, Air Temp, and Snow Depth for " + str(selected_soil_station))


# grid

bx.grid()


# set legend location

bx.legend(bbox_to_anchor=(1.05, 1), loc='upper left')


# remove margin spaces

plt.margins(0, 0)


plt.show()

https://img3.sycdn.imooc.com/6512790b0001b02806530341.jpg

查看完整回答
反對 回復 2023-09-26
  • 1 回答
  • 0 關注
  • 95 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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