Open In App

Python Seaborn’s set_hls_values() Method

Seaborn is a powerful Python data visualization library built on top of Matplotlib. It offers a variety of functions to create visually appealing plots effortlessly. One such function is set_hls_values(), which allows users to customize the hue, lightness, and saturation values of Seaborn's default color palette. In this article, we will learn about Python seaborn.set_hls_values() method.

Python Seaborn's set_hls_values() Method

Seaborn set_hls_values() method is a utility function that allows users to modify the hue, lightness, and saturation values of a color palette. It provides a convenient way to adjust the overall appearance of plots by manipulating these color attributes.

Syntax:

seaborn.set_hls_values(h=None, l=None, s=None)

Parameters:

  • h: Float or None. Specifies the hue value. If None, the default hue is used.
  • l: Float or None. Specifies the lightness value. If None, the default lightness is used.
  • s: Float or None. Specifies the saturation value. If None, the default saturation is used.

Returns: new color code in RGB tuple representation

Seaborn's set_hls_values() Method Examples

Below are some of the examples of Python Seaborn's set_hls_values() Method:

Example 1: Customizing Color Palette with set_hls_values() Method

In this example, we demonstrate how to customize the color palette of a seaborn scatter plot using the set_hls_values() method. The hue, lightness, and saturation values are adjusted to create a custom color palette with a base palette of 'red'.

import seaborn as sns
import pandas as pd

# Sample dataset
data = pd.DataFrame({
    'x': [1, 2, 3, 4, 5],
    'y': [2, 3, 1, 5, 4],
    'category': ['A', 'B', 'A', 'B', 'A']
})

sns.set_hls_values(color='husl', h=0.6, l=0.6, s=0.8)

sns.scatterplot(x='x', y='y', hue='category', data=data)

Output:

<Axes: xlabel='x', ylabel='y'>
Article Tags :