[Python] Plot pandas groupby boxplot and dataframe plot in the same figure

Discussão em 'Python' iniciado por Stack, Janeiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    Why the script below does not work? How can I match the groupby boxplot and the DataFrame plot in the same figure?

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt

    fig, axes = plt.subplots(1, 1, figsize=(15, 15))
    n = 480
    ts = pd.DataFrame(np.random.randn(n), index=pd.date_range(start="2014-02-01",periods=n,freq="H"))
    ts.groupby(lambda x: x.strftime("%Y-%m-%d")).boxplot(subplots=False, rot=90, ax = axes)
    ts.plot(ax = axes)
    plt.show()

    Continue reading...

Compartilhe esta Página