繁体   English   中英

如何使用 matplotlib 从 Pandas 数据框列中绘制具有不同标签的子图

[英]How do I plot subplots with different labels from pandas dataframe columns using 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列表中的标签,即precisionrecall

此外,我有一个分组列( semantic_type )我想用来生成一堆配对图,但是当我在hist方法中传递by关键字以按semantic_type对直方图进行分组时,我得到了color kwarg must have one color per data set. 18 data sets and 1 colors were provided的错误color kwarg must have one color per data set. 18 data sets and 1 colors were provided color kwarg must have one color per data set. 18 data sets and 1 colors were provided

我想通了使用子图......小菜一碟。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM