有一些指示,表明在Seaborn Histplot

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

在与海洋绘制的直方图中,当棒重叠时,因为使用

hue
的颜色变化,通常是无法区分的。这使得很难向人们解释情节。当有10个类带有梯度并了解哪种颜色的颜色变得更难时,这将变得越来越困难。因此,我如何在图上或在传说中显示产生的颜色是因为多个棒的覆盖层。

# imports from sklearn.datasets import load_iris from matplotlib import pyplot as plt %matplotlib inline import seaborn as sns # getting the data iris = load_iris(as_frame=True)['frame'] # make the histogram sns.set(rc={'figure.figsize':(20, 5)}) sns.histplot(data=iris, x='sepal length (cm)', hue='target') plt.show()
在高点的区域中显示这一点:

enter image description here 我想坚持使用直方图。

我怎么做?

您可以使用

alpha=1
python python-3.x matplotlib seaborn
1个回答
5
投票

sns.histplot(data=iris, x='sepal length (cm)', hue='target', alpha=1)

但是,注意,如果在后面显示的串系中显示的系列栏,则该系列的栏上的栏可能更高。

然后,替代方案是使用

displot

拥有一个图表。 histplotsns.displot(data=iris, x='sepal length (cm)', row='target', alpha=1, kind='hist')

NB。我用

iris = sns.load_dataset('iris')加载数据集,图形中的不同名称。 displotiris = sns.load_dataset('iris') sns.histplot(data=iris, x='sepal_length', hue='species', alpha=1) sns.displot(data=iris, x='sepal_length', row='species', alpha=1, kind='hist')

您需要更改单个补丁的zorder

(对应于每个类别的每个bin)。
def RemoveTransperancy(ax): x_bins = defaultdict(list) for p in ax.patches: x_bins[p.get_x()].append(p) for x_value in x_bins: x_bins[x_value].sort(key=lambda p: p.get_height(), reverse=True) for p in ax.patches: p.set_zorder(x_bins[p.get_x()].index(p) + 1)


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.