したがって、次のようなデータがあります。
Observed WRF
2014-06-28 12:00:00 0.000000 1.823554
2014-06-28 13:00:00 0.000000 1.001567
2014-06-28 14:00:00 0.000000 0.309840
2014-06-28 15:00:00 0.000000 0.889811
2014-06-28 16:00:00 0.000000 0.939780
2014-06-28 17:00:00 1.251794 1.271781
2014-06-28 18:00:00 1.610596 0.935092
2014-06-28 19:00:00 2.129068 0.868775
2014-06-28 20:00:00 2.326501 0.892550
...
2014-08-31 05:00:00 0.365868 2.463277
2014-08-31 06:00:00 0.281729 1.233760
2014-08-31 07:00:00 0.197590 0.427411
2014-08-31 08:00:00 0.127754 0.299558
2014-08-31 09:00:00 0.000000 0.571106
2014-08-31 10:00:00 0.000000 0.449634
2014-08-31 11:00:00 0.000000 0.324269
2014-08-31 12:00:00 0.000000 1.725650
そして、2 つの異なる色の箱ひげ図を含むグラフを作成したいと考えています。さて、私は最初からボックスプロットをプロットするのが得意ではないので、私のテクニックがうまくいかないかもしれません. 次のコードを作成しました。
df7.boxplot(by='day',whis=[10,90],sym=' ',figsize=(16,8),color=((1,0.502,0),'black'))\
.legend(loc='lower center', bbox_to_anchor=(1.007, -0.06),prop={'size':16})
plt.subplots_adjust(left=.1, right=0.9, top=0.9, bottom=.2)
plt.title('Five Day WRF Model Comparison Near %.2f,%.2f' %(lat,lon),fontsize=24)
plt.ylabel('Hourly Wind Speed [$W/m^2$]',fontsize=18,color='black')
ax7=plt.gca()
ax7.xaxis.set_label_coords(0.5, -0.05)
plt.xlabel('Time',fontsize=18,color='black')
plt.show()
それから私に与えます:
File "<ipython-input-35-9945f2efb84e>", line 1, in <module>
df7.boxplot(by='D',whis=[10,90],sym=' ',figsize=(16,8),color=((1,0.502,0),'black')).legend(loc='lower center', bbox_to_anchor=(1.007, -0.06),prop={'size':16})
File "...\Anaconda2\lib\site-packages\pandas\core\frame.py", line 5581, in boxplot
return_type=return_type, **kwds)
File "...\Anaconda2\lib\site-packages\pandas\tools\plotting.py", line 2747, in boxplot
return_type=return_type)
File "...\Anaconda2\lib\site-packages\pandas\tools\plotting.py", line 3139, in _grouped_plot_by_column
grouped = data.groupby(by)
File "...\Anaconda2\lib\site-packages\pandas\core\generic.py", line 3778, in groupby
**kwargs)
File "...\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 1427, in groupby
return klass(obj, by, **kwds)
File "...\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 354, in __init__
mutated=self.mutated)
File "...\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 2383, in _get_grouper
in_axis, name, gpr = True, gpr, obj[gpr]
File "...\Anaconda2\lib\site-packages\pandas\core\frame.py", line 1997, in __getitem__
return self._getitem_column(key)
File "...\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2004, in _getitem_column
return self._get_item_cache(key)
File "...\Anaconda2\lib\site-packages\pandas\core\generic.py", line 1350, in _get_item_cache
values = self._data.get(item)
File "...\Anaconda2\lib\site-packages\pandas\core\internals.py", line 3290, in get
loc = self.items.get_loc(item)
File "...\Anaconda2\lib\site-packages\pandas\indexes\base.py", line 1947, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:4154)
File "pandas\index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas\index.c:4018)
File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12368)
File "pandas\hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12322)
KeyError: 'D'
箱ひげ図を日または月ごとに並べ替え、それぞれを同じグラフに 2 つの異なる色、つまり 1 つのオレンジともう 1 つの黒を基本的に重ねてプロットし、2 つの違いを識別できるようにしたいと考えています。大きな混乱のように見えずにこれが不可能な場合は、1 つの図のサブプロットである 2 つの異なるグラフにプロットします (私はそれを行うことができます)。ただし、並べ替えはうまくいかないようです。私の日時インデックスが日または7日でソートできない理由がわかりません。私も試してみました
df7.boxplot(by=df07.index.day,whis=[10,90],sym=' ',figsize=(16,8),color=((1,0.502,0),'black'))\
.legend(loc='lower center', bbox_to_anchor=(1.007, -0.06),prop={'size':16})
...
それから私に与えます:
AssertionError: Grouper and axis must be same length
何が起こっているのかわかりませんが、 を認識しdatetimeIndex
ていないようですがdf7.info()
、戻ってきます:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1542 entries, 2014-06-28 12:00:00 to 2014-08-31 12:00:00
Data columns (total 2 columns):
Observed 1542 non-null float64
WRF 1542 non-null float64
dtypes: float64(2)
memory usage: 36.1 KB
ということで、フォーマットされているようdatetimeIndex
です。
あらゆるご支援に感謝いたします。さらに明確にする必要がある場合は、喜んで追加情報を提供させていただきます。