gpt4 book ai didi

python - 创建一个 fiddle 图的正确方法是什么,其中一把 fiddle 按色调分开?

转载 作者:行者123 更新时间:2023-11-28 22:20:38 25 4
gpt4 key购买 nike

创建将一把 fiddle 按 hue 分割的 fiddle 情节的正确方法是什么?

我尝试了不同的方法,似乎唯一的方法是为数据集中的每个条目创建一个共享相同值的特征。并将该功能的名称作为 x 传递。

fig = plt.figure(figsize=(20, 8))

fig.add_subplot(1, 3, 1)
ax = sns.violinplot(x='feature', y='height',
data=train_cleansed_height,
scale='count',
hue='feature', split=True,
palette='seismic',
inner='quartile')

fig.add_subplot(1, 3, 2)
ax = sns.violinplot(x='workaround', y='height',
data=train_cleansed_height,
scale='count',
hue='feature', split=True,
palette='seismic',
inner='quartile')

fig.add_subplot(1, 3, 3)
ax = sns.violinplot(x=None, y='height',
data=train_cleansed_height,
scale='count',
hue='feature', split=True,
palette='seismic',
inner='quartile')
plt.xlabel('x=None')

Violin plot example

但这是正确的方法吗?

最佳答案

seaborn.violinplotx 参数需要是位置的数据。如果需要单个位置,则 x 的数据需要包含唯一值。如果为 xhue 选择相同的数据,x 将被赋予两个不同的唯一值,因此选择了两个位置,如在第一个情节中看到。

而是使用像

这样的重复标签
sns.violinplot(x=["some label"]*len(df),  ...) 

在单个位置创建 fiddle 图。

import numpy as np;np.random.seed(1)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

a = np.concatenate((np.random.binomial(3,0.3,50)*2.2+1, np.random.rayleigh(3,50)))
df = pd.DataFrame({"height" : a, "feature" : ["A"]*50+["B"]*50})

fig = plt.figure()

fig.add_subplot(1, 2, 1)
ax = sns.violinplot(x='feature', y='height',
data=df,
scale='count',
hue='feature', split=True,
palette='seismic',
inner='quartile')

fig.add_subplot(1, 2, 2)
ax = sns.violinplot(x=["AB"]*len(df), y='height',
data=df,
scale='count',
hue='feature', split=True,
palette='seismic',
inner='quartile')

plt.tight_layout()
plt.show()

enter image description here

关于python - 创建一个 fiddle 图的正确方法是什么,其中一把 fiddle 按色调分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48803619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com