在同一图中绘制 pandas groupby 箱线图和数据框图

问题描述 投票:0回答:1

为什么下面的脚本不起作用?如何在同一图中匹配 groupby 箱线图和 DataFrame 图?

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()
python pandas group-by boxplot
1个回答
0
投票
g = ts.groupby(lambda x: x.strftime("%Y-%m-%d")).boxplot(subplots=False, rot=90, ax = axes)
g.plot(ax = axes)
plt.show()

plot

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.