Multiple histograms in Pandas

后端 未结 5 1462
攒了一身酷
攒了一身酷 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:43

    You make two dataframes and one matplotlib axis

    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy as np
    
    df1 = pd.DataFrame({
        'data1': np.random.randn(10),
        'data2': np.random.randn(10)
    })
    
    df2 = df1.copy()
    
    fig, ax = plt.subplots()
    df1.hist(column=['data1'], ax=ax)
    df2.hist(column=['data2'], ax=ax)
    

提交回复
热议问题