直方图的每个子图中的标签箱

时间:2018-11-18 06:33:05

标签: python pandas matplotlib

我有一个数据框,df有29行乘24列的尺寸

                     Index             0.0      5.0     34.0 ... 22.0 
          2017-08-03 00:00:00           10        0      10       0
          2017-08-04 00:00:00           20       60    1470      20
          2017-08-05 00:00:00           0        58       0      24
          2017-08-06 00:00:00           0         0     480      24
          2017-09-07 00:00:00           0         0       0      25
                   :                    :         :       :      :
                   :                    :         :       :      :
         2017-09-30 00:00:00

我打算在表示直方图的一列的每个子图上标记bin。使用此代码,我已经能够在每一列的每个子图中绘制直方图

fig = plt.figure(figsize = (15,20))
ax = fig.gca()
#Initialize the figure
plt.style.use('seaborn-darkgrid')
df.hist(ax = ax) 

但是,每个子图的bin的标签相距很远,并且bin标签没有通过x轴上的范围明确指定,这很难解释。我看过     Aligning bins to xticks in plt.hist,但在涉及子图时,它并没有明确解决标签箱的问题。任何帮助都会很棒...

我也尝试过此方法,但出现ValueError:太多值无法解包(预期2)

x=[0,40,80,120,160,200,240,280,320]
fig = plt.figure(figsize = (15,20))
ax = fig.gca()
# Initialize the figure
plt.style.use('seaborn-darkgrid')
n,bins= plt.hist(df,bins= x)
#labels & axes
plt.locator_params(nbins=8, axis='x')
plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
plt.title('Daily occurrence',fontsize=16)
plt.xlabel('Number of occurrence',fontsize=12)
plt.ylabel('Frequency',fontsize=12)
plt.xticks(x)
plt.xlim(0,320)

0 个答案:

没有答案
相关问题