そのため、複数のデータ ファイルがあり、そのすべてが情報を簡単に処理するためにデータフレームを使用しています。ファイルはすべて NetCDF ファイルです。同じ図に 4 つの boxplot グラフをプロットして、すべてを簡単に比較できるようにしようとしています (同じ時間の選択範囲の平均が異なる時間にどのようにピークに達するかを見ています)。これはわずかに異なる時間間隔で取得された観測データであり、異なる変数番号は異なる時間依存変数に対応するため、X 値と Y 値は異なります。
サブプロットを使用して、matplotlib を使用してこれを実現しようとしましたが、3 つの空のグラフが吐き出されるだけです。どうすればこれを実現できますか?
コードは次のとおりです。
plt.figure(1)
plt.subplot(2, 1, 1)
ds1 = xr.open_dataset(lfile1)
one_day1 = ds1[variable1].sel(time=slice(monthofi+startday+' '+starttime,monthofi+endday+' '+endtime))
df1 = one_day1.to_pandas().to_frame(name=variable1)
df1.index=df1.index-pd.DateOffset(hours=7)
df1.boxplot(column=variable1, by=df1.index.time, whis=[10, 90], sym='')
plt.xlabel('Time')
plt.ylabel('Temperature [degF]')
plt.title('Daily Cycle')
plt.suptitle('')
plt.subplot(2, 1, 2)
ds2 = xr.open_dataset(lfile2)
one_day2 = ds2[variable2].sel(time=slice(monthofi+startday+' '+starttime,monthofi+endday+' '+endtime))
df2 = one_day2.to_pandas().to_frame(name=variable2)
df2.index=df2.index-pd.DateOffset(hours=7)
df2.boxplot(column=variable2, by=df2.index.time, whis=[10, 90], sym='')
plt.xlabel('Time')
plt.ylabel('Average Wind Speed')
plt.title('Daily Cycle')
plt.suptitle('')
plt.subplot(2, 2, 1)
ds3 = xr.open_dataset(lfile3)
one_day3 = ds3[variable3].sel(time=slice(monthofi+startday+' '+starttime,monthofi+endday+' '+endtime))
df3 = one_day3.to_pandas().to_frame(name=variable3)
df3.index=df1.index-pd.DateOffset(hours=7)
df3.boxplot(column=variable3, by=df3.index.time, whis=[10, 90], sym='')
plt.xlabel('Time')
plt.ylabel('Wind Direction')
plt.title('Daily Cycle')
plt.suptitle('')
plt.subplot(2, 2, 2)
ds4 = xr.open_dataset(lfile4)
one_day4 = ds4[variable4].sel(time=slice(monthofi+startday+' '+starttime,monthofi+endday+' '+endtime))
df4 = one_day4.to_pandas().to_frame(name=variable4)
df4.index=df4.index-pd.DateOffset(hours=7)
df4.boxplot(column=variable4, by=df4.index.time, whis=[10, 90], sym='')
plt.xlabel('Time')
plt.ylabel('Solar Radiation [W/m^2]')
plt.title('Daily Cycle')
plt.suptitle('')
plt.show()
正確に何が起こっていないのですか?
さて、次のように編集しました。
plt.figure()
ax1 = plt.subplot(2, 2, 1)
df1.boxplot(column=variable1, by=df1.index.time, whis=[10, 90], sym='')
ax1.set_title('Daily Cycle')
ax2 = plt.subplot(2, 2, 2)
df2.boxplot(column=variable2, by=df2.index.time, whis=[10, 90], sym='')
ax2.set_title('Daily Cycle')
ax3 = plt.subplot(2, 2, 3)
df3.boxplot(column=variable3, by=df3.index.time, whis=[10, 90], sym='')
ax3.set_title('Daily Cycle')
ax4 = plt.subplot(2, 2, 4)
df4.boxplot(column=variable4, by=df4.index.time, whis=[10, 90], sym='')
ax4.set_title('Daily Cycle')
plt.show()
今、私は 5 つの図を持つ 5 つのウィンドウを取得しています。ウィンドウ全体を占める 1 つの図には、4 つのサブプロットにある必要があるすべてのデータが含まれていますが、他の 4 つの図には、希望する位置にそれぞれサブプロットがありますが、空です。