python - 将 pandas groupby 直方图绘制为子图
问题描述
我有两个要绘制的数据框。我可以使用以下内容:
def make_plots():
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,5))
with open(filen, 'rt') as f:
dfn = pd.read_csv(f, delimiter='\t')
dfn.plot(x='pos', ax=axes[0])
with open(filem, 'rt') as f:
dfm = pd.read_csv(f, delimiter='\t')
dfm.plot(x='pos', ax=axes[1])
fig.savefig('outfig.png')
但是,如果我的第二个图是带有组的直方图,则此代码将失败。就像是:
def make_plots():
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,5))
with open(filen, 'rt') as f:
dfn = pd.read_csv(f, delimiter='\t')
dfn.plot(x='pos', ax=axes[0])
with open(filem, 'rt') as f:
dfm = pd.read_csv(f, delimiter='\t')
dfm.hist(by='groupname', ax=axes[1])
fig.savefig('outfig.png')
我希望得到的是一个 12x5 的图形,其中左侧 6x5 部分用于第一个图,右侧 6x5 部分包含两个直方图,每个直方图占用大约 3x5。
解决方案
推荐阅读
- indexing - AEM : 房地产指数
- download - 下载带有依赖项的巧克力包,但稍后安装
- php - 无法在 Ubuntu 18.04 上加载 SimpleXML
- powershell - 使用 Powershell 将新的 O365 用户添加到 AD 组
- django - 如何使用 django 更改 url 以显示描述而不是 id?
- azure-cosmosdb - 批量插入 Azure Cosmos DB
- codespaces - 在 VS Codespace 中复制一行的快捷键是什么
- python - Python 初始化失败,没有名为“编码”的模块错误
- reactjs - 使用 react dropzone 显示文件名
- perforce - perforce -m 属性为 clean 不在文档中