我試圖繪制的功能min (),并max ()在同一張圖,我已經可以用的功能max (),但我怎么能在同一圖表中加入了兩個它可以正確顯示?我的代碼和輸出示例:
df.groupby('fecha_inicio')['capacidad_base_firme'].max().plot(kind='bar', legend = 'Reverse')
plt.xlabel('Tarifa de Base firme por Zona')

我的資料框的輸出:
zona capacidad_base_firme ... fecha_inicio fecha_fin
0 Sur 1.52306 ... 2016-01-01 2016-03-31
1 Centro 2.84902 ... 2016-01-01 2016-03-31
2 Occidente 1.57302 ... 2016-01-01 2016-03-31
3 Golfo 3.06847 ... 2016-01-01 2016-03-31
4 Norte 4.34706 ... 2016-01-01 2016-03-31
.. ... ... ... ... ...
67 Golfo 5.22776 ... 2017-10-01 2017-12-31
68 Norte 6.99284 ... 2017-10-01 2017-12-31
69 Istmo 7.25957 ... 2017-10-01 2017-12-31
70 Nacional 0.21971 ... 2017-10-01 2017-12-31
71 Nacional con AB -0.72323 ... 2017-10-01 2017-12-31
[72 rows x 10 columns]
uj5u.com熱心網友回復:
- 正確的方法是用 將多個指標同時聚合
- 使用
stacked=True的堆疊條
ax = dfg.plot(kind='bar', figsize=(8, 6), title='Bill Length (mm)', xlabel='Species', ylabel='Length (mm)', rot=0, stacked=True)
uj5u.com熱心網友回復:
第1步
創建一個子圖來繪制資料
fig, ax = plt.subplots()第2步
將 DataFrame 最大值和最小值繪制到特定軸
df.groupby('fecha_inicio')['capacidad_base_firme'].max().plot(ax = ax, kind='bar', legend = 'Reverse', label='Maximum') df.groupby('fecha_inicio')['capacidad_base_firme'].min().plot(ax = ax, kind='bar', legend = 'Reverse', label='Minimum')您可能需要調整zorder以獲得堆積條形圖的效果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/371221.html標籤:Python 熊猫 matplotlib 通过...分组 条形图
上一篇:在坐標系中顯示整數點
- 使用
