如何获得分组条形图?

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

我是seaborn的新手,我想绘制条形图。我从一个csv文件导入数据。我想让这些条形图的宽度小一些,并且对一个类别进行分组连接,但是,我发现这些条形图之间有很多空格。但是,我在这些图形之间得到了很多空格。有没有一种方法可以让我解决上述问题。注意,我的y轴范围是从80到100,我需要保持这个范围。

目前我使用的代码是。

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
import pandas as pd
Data=pd.read_csv('S_Data.csv')
plt.figure(figsize=(20,5))
ax = sns.barplot(x="Techniques on data", y="Test Accuracy", hue="Epochs",  order = ['WNO + FIFO', 'WNO', 'WNO + on_combined data', 'WNO + replace with gsd'], palette="Blues_d", data=Data)

def change_width(ax, new_value) :
    for patch in ax.patches :
        current_width = patch.get_width()
        diff = current_width - new_value

        # we change the bar width
        patch.set_width(new_value)

        # we recenter the bar
        patch.set_x(patch.get_x() + diff * .5)
change_width(ax, .10)
ax.set_ylim(80,100)
ax.set_title('Result')

enter image description here先谢谢你

python matplotlib bar-chart data-visualization seaborn
1个回答
0
投票

考虑使用 countplot 而非 barplot 功能。 [链接]. 我相信,根据你的 hue="Epochs"在不使用额外功能的情况下,你就能实现瘦身吧的风格。

© www.soinside.com 2019 - 2024. All rights reserved.