- The correct approach to setting the color of a single group, depends on how, or if,
data=
is specified, and if x=
, or y=
, is specified.
- The same issue applies to
g = sns.histplot(data=df, color='r', legend=False)
, as shown in this plot.
- The same implementations work with
histplot
.
- Tested in
python 3.11.3
, matplotlib 3.7.1
, seaborn 0.12.2
Imports and Data
import numpy as np
import seaborn as sns
# random normal data as a list
np.random.seed(2023)
res = np.random.normal(loc=75, scale=5, size=1000).tolist()
# create a dataframe
df = pd.DataFrame(res)
# df.head() - the column header is the number 0, not string '0'
0
0 78.558368
1 73.377575
2 69.990647
3 76.181254
4 74.489201
Plot Implementation
- Pass
df
, and do not specify a column name for x=
, requires passing a dict
or a list
to palette
.
palette
will also accept a string, but the string must be a valid palette name, ValueError: 'r' is not a valid palette name
- The color saturation is different when using
palette
, compared to color
, so pass alpha=
(number 0 - 1) to adjust as needed.
g = sns.displot(data=df, palette={0: 'r'})
g = sns.displot(data=df, palette=['r'])
- Pass
df
, and specify a column name for x=
g = sns.displot(data=df, x=0, color='r')
g = sns.displot(x=df[0], color='r')
- Pass
res
directly to data=
g = sns.displot(data=res, color='r')
g = sns.displot(x=res, color='r')

