更改seaborn boxplot line rainb

2024-05-23 21:45:29 发布

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

我在网上找到了这张漂亮的图表(显然是用plotly制作的),想用seaborn重新制作它。 enter image description here

这是我目前为止的代码:

import pandas as pd
import seaborn as sns

data = ...

flierprops = dict(marker='o', markersize=3)
sns.boxplot(x="label", y="mean",palette="husl", data=data,saturation=1,flierprops=flierprops)

到目前为止的结果是:

enter image description here

我已经很高兴了,但我想调整行和离群值颜色以匹配husl颜色托盘。我该怎么做?(以及附加说明:如何更改线宽?)在


Tags: 代码importpandasdata颜色as图表seaborn
1条回答
网友
1楼 · 发布于 2024-05-23 21:45:29

考虑两个SO解决方案:

  1. @tmdavison's solution编辑线条和点颜色的Line2D对象
  2. @IanHincks's solution为边框设置浅色/深色matplotlib颜色

数据

import numpy as np
import pandas as pd

data_tools = ['sas', 'stata', 'spss', 'python', 'r', 'julia']

### DATA BUILD
np.random.seed(4122018)
random_df = pd.DataFrame({'group': np.random.choice(data_tools, 500),
                          'int': np.random.randint(1, 10, 500),
                          'num': np.random.randn(500),
                          'bool': np.random.choice([True, False], 500),
                          'date': np.random.choice(pd.date_range('2019-01-01', '2019-04-12'), 500)
                           }, columns = ['group', 'int', 'num', 'char', 'bool', 'date'])

绘图(生成两个:原始和调整)

^{pr2}$

Plot Outputs


对于您的特定绘图,为boxplot设置一个轴,然后迭代其MPL艺术家:

^{3}$

相关问题 更多 >