我正在使用 seaborn 创建箱线图。当我指定一列对框进行分组/着色时,框的宽度变得非常窄,以至于很难看到。我所做的唯一更改是为hue 指定一个参数,它指向传递的数据帧中的一列。我曾尝试使用 'width' 参数(如前所述 here ),它确实增加了箱线图的宽度,但也增加了它们分开的距离。
帮助:如何在指定色调参数时保持框的宽度?
我将在下面展示我的代码和结果:
我的数据框:
Out[3]:
timestamp room_number floor floor_room temperature
0 2016-01-19 09:00:00-05:00 11a06 11 11_11a06 23.0
1 2016-01-19 09:00:00-05:00 east-inner 11 11_east-inner 22.8
2 2016-01-19 09:00:00-05:00 east-window 11 11_east-window 22.9
使用具有奇数箱线图宽度的 seaborn,使用分组因子:
sns.boxplot(x=xunit, y=var, data=df, order=order, hue='floor')
使用具有合理箱线图宽度但没有分组因子的 seaborn:
sns.boxplot(x=xunit, y=var, data=df)
最佳答案
在 0.8 版(2017 年 7 月)中,dodge
添加了参数
to
boxplot
,violinplot
, andbarplot
to allow use ofhue
without changing the position or width of the plot elements, as when thehue
varible is not nested within the main categorical variable.
( release notes v0.8.0 )
您的代码如下所示:
sns.boxplot(x=xunit, y=var, data=df, order=order, hue='floor', dodge=False)
关于boxplot - 选择色调后,Seaborn boxplots 会更改(缩小)框的宽度,我该如何补救?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36092363/