or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

categorical-plots.mdcolor-palettes.mddistribution-plots.mdgrid-plots.mdindex.mdinteractive-widgets.mdmatrix-plots.mdobjects-interface.mdrelational-plots.mdstyling-themes.mdutilities.md

color-palettes.mddocs/

0

# Color Palettes

1

2

Generate and customize color palettes including sequential, diverging, qualitative, and perceptually uniform palettes. These functions provide sophisticated color schemes for data visualization with options for specific color spaces and custom palette creation.

3

4

## Capabilities

5

6

### HUSL Color Space Palettes

7

8

Generate evenly spaced colors in HUSL (human-friendly HSL) color space.

9

10

```python { .api }

11

def husl_palette(n_colors=6, h=0.01, s=0.9, l=0.65, as_cmap=False):

12

"""

13

Get a set of evenly spaced colors in HUSL hue space.

14

15

Parameters:

16

- n_colors: int, number of colors in the palette

17

- h: float or tuple, hue value or range (0-1)

18

- s: float or tuple, saturation value or range (0-1)

19

- l: float or tuple, lightness value or range (0-1)

20

- as_cmap: bool, return matplotlib Colormap object

21

22

Returns:

23

list of RGB tuples or matplotlib Colormap

24

"""

25

```

26

27

### HLS Color Space Palettes

28

29

Generate evenly spaced colors in HLS color space.

30

31

```python { .api }

32

def hls_palette(n_colors=6, h=0.01, l=0.6, s=0.65, as_cmap=False):

33

"""

34

Get a set of evenly spaced colors in HLS hue space.

35

36

Parameters:

37

- n_colors: int, number of colors in the palette

38

- h: float or tuple, hue value or range (0-1)

39

- l: float or tuple, lightness value or range (0-1)

40

- s: float or tuple, saturation value or range (0-1)

41

- as_cmap: bool, return matplotlib Colormap object

42

43

Returns:

44

list of RGB tuples or matplotlib Colormap

45

"""

46

```

47

48

### Cubehelix Palettes

49

50

Create sequential palettes using the cubehelix color system.

51

52

```python { .api }

53

def cubehelix_palette(

54

n_colors=6,

55

start=0,

56

rot=0.4,

57

gamma=1.0,

58

hue=0.8,

59

light=0.85,

60

dark=0.15,

61

reverse=False,

62

as_cmap=False

63

):

64

"""

65

Make a sequential palette from the cubehelix system.

66

67

Parameters:

68

- n_colors: int, number of colors in the palette

69

- start: float, starting color (0-3)

70

- rot: float, rotation amount (-1 to 1)

71

- gamma: float, gamma correction factor

72

- hue: float, saturation intensity

73

- light: float, lightest color (0-1)

74

- dark: float, darkest color (0-1)

75

- reverse: bool, reverse the palette direction

76

- as_cmap: bool, return matplotlib Colormap object

77

78

Returns:

79

list of RGB tuples or matplotlib Colormap

80

"""

81

```

82

83

### Light Sequential Palettes

84

85

Create palettes that blend from light colors to a specified color.

86

87

```python { .api }

88

def light_palette(color, n_colors=6, reverse=False, as_cmap=False, input="rgb"):

89

"""

90

Make a sequential palette that blends from light to a color.

91

92

Parameters:

93

- color: str or tuple, base color specification

94

- n_colors: int, number of colors in the palette

95

- reverse: bool, reverse the palette direction

96

- as_cmap: bool, return matplotlib Colormap object

97

- input: str, color input format ("rgb", "hls", "husl", "xkcd")

98

99

Returns:

100

list of RGB tuples or matplotlib Colormap

101

"""

102

```

103

104

### Dark Sequential Palettes

105

106

Create palettes that blend from dark colors to a specified color.

107

108

```python { .api }

109

def dark_palette(color, n_colors=6, reverse=False, as_cmap=False, input="rgb"):

110

"""

111

Make a sequential palette that blends from dark to a color.

112

113

Parameters:

114

- color: str or tuple, base color specification

115

- n_colors: int, number of colors in the palette

116

- reverse: bool, reverse the palette direction

117

- as_cmap: bool, return matplotlib Colormap object

118

- input: str, color input format ("rgb", "hls", "husl", "xkcd")

119

120

Returns:

121

list of RGB tuples or matplotlib Colormap

122

"""

123

```

124

125

### Diverging Palettes

126

127

Create diverging palettes between two colors in HUSL space.

128

129

```python { .api }

130

def diverging_palette(

131

h_neg,

132

h_pos,

133

s=75,

134

l=50,

135

sep=1,

136

n=6,

137

center="light",

138

as_cmap=False

139

):

140

"""

141

Make a diverging palette between two HUSL colors.

142

143

Parameters:

144

- h_neg: float, hue for negative side (0-359)

145

- h_pos: float, hue for positive side (0-359)

146

- s: float, saturation (0-100)

147

- l: float, lightness (0-100)

148

- sep: int, separation between negative and positive sides

149

- n: int, number of colors in the palette

150

- center: str, center color ("light", "dark")

151

- as_cmap: bool, return matplotlib Colormap object

152

153

Returns:

154

list of RGB tuples or matplotlib Colormap

155

"""

156

```

157

158

### Blended Palettes

159

160

Blend between multiple colors to create custom palettes.

161

162

```python { .api }

163

def blend_palette(colors, n_colors=6, as_cmap=False, input="rgb"):

164

"""

165

Blend between a list of colors to make a new palette.

166

167

Parameters:

168

- colors: list, sequence of colors to blend

169

- n_colors: int, number of colors in resulting palette

170

- as_cmap: bool, return matplotlib Colormap object

171

- input: str, color input format ("rgb", "hls", "husl", "xkcd")

172

173

Returns:

174

list of RGB tuples or matplotlib Colormap

175

"""

176

```

177

178

### XKCD Color Palettes

179

180

Create palettes using XKCD color names.

181

182

```python { .api }

183

def xkcd_palette(colors):

184

"""

185

Make a palette from XKCD color names.

186

187

Parameters:

188

- colors: list, XKCD color names

189

190

Returns:

191

list of RGB tuples

192

193

Available colors accessible via sns.colors.xkcd_rgb dictionary

194

"""

195

```

196

197

### Crayon Color Palettes

198

199

Create palettes using Crayola crayon color names.

200

201

```python { .api }

202

def crayon_palette(colors):

203

"""

204

Make a palette from Crayola crayon colors.

205

206

Parameters:

207

- colors: list, crayon color names

208

209

Returns:

210

list of RGB tuples

211

212

Available colors accessible via sns.colors.crayons dictionary

213

"""

214

```

215

216

### Matplotlib Palette Interface

217

218

Return discrete colors from matplotlib colormaps.

219

220

```python { .api }

221

def mpl_palette(name, n_colors=6, as_cmap=False):

222

"""

223

Return discrete colors from a matplotlib palette.

224

225

Parameters:

226

- name: str, matplotlib colormap name

227

- n_colors: int, number of discrete colors

228

- as_cmap: bool, return matplotlib Colormap object

229

230

Returns:

231

list of RGB tuples or matplotlib Colormap

232

"""

233

```

234

235

## Built-in Palettes

236

237

### Qualitative Palettes

238

239

- **"deep"**: Rich, saturated colors (default)

240

- **"muted"**: Muted versions of default colors

241

- **"bright"**: Bright, saturated colors

242

- **"pastel"**: Light, pastel colors

243

- **"dark"**: Dark versions of default colors

244

- **"colorblind"**: Colorblind-friendly palette

245

246

### Sequential Palettes

247

248

- **"rocket"**: Black to orange/yellow

249

- **"mako"**: Black to blue/green

250

- **"flare"**: Light to dark orange/red

251

- **"crest"**: Light to dark blue/green

252

253

### Diverging Palettes

254

255

- **"vlag"**: Blue to red through light gray

256

- **"icefire"**: Blue to red through white

257

258

## Usage Examples

259

260

### Basic Color Palette

261

262

```python

263

import seaborn as sns

264

import matplotlib.pyplot as plt

265

266

# Show a palette

267

palette = sns.color_palette("husl", 8)

268

sns.palplot(palette)

269

plt.show()

270

271

# Use in a plot

272

tips = sns.load_dataset("tips")

273

sns.scatterplot(data=tips, x="total_bill", y="tip", hue="day", palette="husl")

274

plt.show()

275

```

276

277

### HUSL Palette

278

279

```python

280

# Custom HUSL palette

281

husl_colors = sns.husl_palette(6, h=0.5, s=0.8, l=0.6)

282

sns.palplot(husl_colors)

283

plt.show()

284

```

285

286

### Cubehelix Palette

287

288

```python

289

# Cubehelix sequential palette

290

cube_palette = sns.cubehelix_palette(8, start=0.5, rot=-0.75)

291

sns.palplot(cube_palette)

292

plt.show()

293

294

# Use as colormap

295

data = sns.load_dataset("flights").pivot("month", "year", "passengers")

296

sns.heatmap(data, cmap=sns.cubehelix_palette(as_cmap=True))

297

plt.show()

298

```

299

300

### Light and Dark Palettes

301

302

```python

303

# Light to color palette

304

light_blue = sns.light_palette("navy", 6)

305

sns.palplot(light_blue)

306

plt.show()

307

308

# Dark to color palette

309

dark_green = sns.dark_palette("seagreen", 6, reverse=True)

310

sns.palplot(dark_green)

311

plt.show()

312

```

313

314

### Diverging Palette

315

316

```python

317

# Custom diverging palette

318

diverging = sns.diverging_palette(220, 20, n=7, center="dark")

319

sns.palplot(diverging)

320

plt.show()

321

322

# Use in heatmap

323

correlation = tips.select_dtypes(include=['float64']).corr()

324

sns.heatmap(correlation, cmap=diverging, center=0, annot=True)

325

plt.show()

326

```

327

328

### Blend Palette

329

330

```python

331

# Blend between multiple colors

332

colors = ["red", "orange", "yellow", "green", "blue"]

333

blended = sns.blend_palette(colors, 10)

334

sns.palplot(blended)

335

plt.show()

336

```

337

338

### XKCD Colors

339

340

```python

341

# Use XKCD color names

342

xkcd_colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"]

343

xkcd_palette = sns.xkcd_palette(xkcd_colors)

344

sns.palplot(xkcd_palette)

345

plt.show()

346

```

347

348

### Crayon Colors

349

350

```python

351

# Use Crayola crayon colors

352

crayon_colors = ["Red", "Blue", "Yellow", "Green", "Purple"]

353

crayon_palette = sns.crayon_palette(crayon_colors)

354

sns.palplot(crayon_palette)

355

plt.show()

356

```

357

358

### Matplotlib Colormap

359

360

```python

361

# Extract colors from matplotlib colormap

362

viridis_discrete = sns.mpl_palette("viridis", 8)

363

sns.palplot(viridis_discrete)

364

plt.show()

365

```

366

367

### Context-Dependent Palettes

368

369

```python

370

# Different palettes for different contexts

371

with sns.color_palette("husl", 8):

372

# This plot uses HUSL colors

373

sns.boxplot(data=tips, x="day", y="total_bill", hue="smoker")

374

plt.show()

375

376

# Back to default palette

377

sns.boxplot(data=tips, x="day", y="total_bill", hue="smoker")

378

plt.show()

379

```

380

381

## Color Dictionaries

382

383

Access to named color collections:

384

385

```python

386

# XKCD colors (954 colors)

387

xkcd_colors = sns.colors.xkcd_rgb

388

print(list(xkcd_colors.keys())[:10]) # First 10 color names

389

390

# Crayola colors (163 colors)

391

crayon_colors = sns.colors.crayons

392

print(list(crayon_colors.keys())[:10]) # First 10 color names

393

```

394

395

## Types

396

397

```python { .api }

398

# Color specifications

399

ColorSpec = str | tuple[float, float, float] | tuple[float, float, float, float]

400

PaletteSpec = str | list[ColorSpec] | dict

401

402

# Input formats

403

ColorInput = Literal["rgb", "hls", "husl", "xkcd"]

404

405

# Palette types

406

QualitativePalette = Literal["deep", "muted", "bright", "pastel", "dark", "colorblind"]

407

SequentialPalette = Literal["rocket", "mako", "flare", "crest"]

408

DivergingPalette = Literal["vlag", "icefire"]

409

```