Setting axis labels for histogram pandas

前端 未结 1 1428
死守一世寂寞
死守一世寂寞 2021-01-04 19:49

I\'m fairly new to this, so there might be a very obvious answer to this. My apologies!

I\'m plotting two histograms via a groubpy. I\'d like my subplots to each h

1条回答
  •  太阳男子
    2021-01-04 20:41

    Labels are properties of axes objects, that needs to be set on each of them. Here's an example that worked for me:

    frame = pd.DataFrame([np.random.rand(20), np.sign(np.random.rand(20) - 0.5)]).T
    frame.columns = ['Age', 'Survived']
    
    # Note that you can let the hist function do the groupby
    # the function hist returns the list of axes created
    axarr = frame.hist(column='Age', by = 'Survived', sharex=True, sharey=True, layout = (2, 1))
    
    for ax in axarr.flatten():
        ax.set_xlabel("Age")
        ax.set_ylabel("Individuals")
    

    0 讨论(0)
提交回复
热议问题