2017-12-28 41 views
0

私はDateTimeインデックスを持つpandas DataFrameを持っています。matplotlibのx軸日時ラベルの争い

私はそれからtimeseriesをプロットすることができ、デフォルトでは正常に見えます。

しかし、同じDataFrameから棒グラフを印刷しようとすると、xAxisのラベルが壊れてしまいます(大規模なオーバーラップ)。 (また、データの間隔が

)のバーのセットの間に奇妙な(大きなギャップである私はautoformat_xdate()を試してみましたが、それは何も助けにはならなかった。

enter image description here

これは私が使用する単純なコード断片でありますグラフを生成する

entire_df['predict'] = regr.predict(entire_df[X_cols]) 
entire_df['error'] = entire_df['predict']-entire_df['px_usd_mmbtu'] 
#entire_df['error'].plot(kind='hist') 
fig=plt.figure() 
entire_df[['px_usd_mmbtu', 'predict']].plot() 
fig2 = plt.figure() 
entire_df['error'].plot(kind='bar') 
#fig2.autofmt_xdate()    #doesn't help 
print (type(error_df.index)) 

答えて

0

これを試してみてください:

entire_df['predict'] = regr.predict(entire_df[X_cols]) 
entire_df['error'] = entire_df['predict']-entire_df['px_usd_mmbtu'] 

plt.figure(figsize=(15,15)) 
plt.xticks(rotation = 90) # or change from 90 to 45 

#entire_df['error'].plot(kind='hist') 

entire_df[['px_usd_mmbtu', 'predict']].plot() 
entire_df['error'].plot(kind='bar') 
関連する問題