python - 如何使用 matplotlib 从 pandas 数据框列中绘制具有不同标签的子图
问题描述
我有以下代码将熊猫数据框中的列打印为两个直方图:
df = pd.read_csv('fairview_Procedure_combined.csv')
ax = df.hist(column=['precision', 'recall'], bins=25, grid=False, figsize=(12,8), color='#86bf91', zorder=2, rwidth=0.9)
ax = ax[0]
for x in ax:
# Despine
x.spines['right'].set_visible(False)
x.spines['top'].set_visible(False)
x.spines['left'].set_visible(False)
# Switch off ticks
x.tick_params(axis="both", which="both", bottom="off", top="off", labelbottom="on", left="off", right="off", labelleft="on")
# Draw horizontal axis lines
vals = x.get_yticks()
for tick in vals:
x.axhline(y=tick, linestyle='dashed', alpha=0.4, color='#eeeeee', zorder=1)
# Remove title
x.set_title("")
# Set x-axis label
x.set_xlabel("test", labelpad=20, weight='bold', size=12)
# Set y-axis label
x.set_ylabel("count", labelpad=20, weight='bold', size=12)
# Format y-axis label
x.yaxis.set_major_formatter(StrMethodFormatter('{x:,g}'))
它给出了附加的输出:
但是,我希望在 x 轴上有不同的标签(特别是在我的column
列表中列出的标签,即precision
和recall
)
另外,我有一个semantic_type
分组by
列(hist
semantic_type
color kwarg must have one color per data set. 18 data sets and 1 colors were provided
解决方案
我用子图弄清楚了……小菜一碟。
推荐阅读
- implementation - 如何实现闪电网络的 RSMC 部分?
- python - 如何找出 RFECV 选择的特征名称?
- python - 如何同时从单词列表中检查和删除“/”和“-”
- sqlite - sqlite 从列中删除平方米符号
- javascript - 在客户端使用PHP或JavaScript从大量数据中通过大量关键字一一搜索
- jquery - 在通过 ajax 保存之前检查字符长度
- .net-core - 强制更新传递 nuget 包依赖项的最佳方法?
- schedule - 到达率的 AnyLogic 时间表
- vue.js - 如何在安装生命周期方法之前使用 vue.js?
- swift - UIApplication.shared.open 在 ios 13 中不起作用