如何使用seaborn/matplotlib为条形图的标签名称添加背景色

2024-04-25 22:44:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更改条形图中标签的背景色。 我很感兴趣,如果这是某种可能与海伯恩。你知道吗

我已经阅读了文档并搜索了stackoverflow,但是我找不到解决方案。你知道吗

"""
pal is the color palette I am using for my plot 
"""
imported = pd.read_csv("""FILENAME.csv""", sep=";")
    data = imported.filter(items=column_names)

    data.columns = new_names

    for index, row in data.iterrows():

        again_new_df = pd.DataFrame({'name':row.index, 'value':row.values})

        sns.set(style="whitegrid")
        ax = sns.barplot(x='value', y='name', data=again_new_df, palette=pal)
        ax.set(xlabel='common xlabel', ylabel='common ylabel')
        plt.xlim(0, 1)
        plt.show()
        break

为了演示,我在PowerPoint中创建了两个情节,所以我的问题很清楚:

“我当前的情节”:

current_plot

情节应该是这样的:

new_plot


Tags: csvnamedfnewfordataindexnames