Multiple histograms in Pandas

后端 未结 5 1461
攒了一身酷
攒了一身酷 2020-12-05 06:59

I would like to create the following histogram (see image below) taken from the book \"Think Stats\". However, I cannot get them on the same plot. Each DataFrame takes its o

5条回答
  •  误落风尘
    2020-12-05 07:55

    In case anyone wants to plot one histogram over another (rather than alternating bars) you can simply call .hist() consecutively on the series you want to plot:

    %matplotlib inline
    import numpy as np
    import matplotlib.pyplot as plt
    import pandas
    
    
    np.random.seed(0)
    df = pandas.DataFrame(np.random.normal(size=(37,2)), columns=['A', 'B'])
    
    df['A'].hist()
    df['B'].hist()
    

    This gives you:

    Note that the order you call .hist() matters (the first one will be at the back)

提交回复
热议问题