[파이썬] Seaborn 팔레트 설정

When it comes to data visualization in Python, Seaborn is a popular and powerful library that provides a high-level interface for creating aesthetically pleasing and informative plots. One of the key features of Seaborn is its ability to customize the color palette for your plots.

A color palette is a collection of colors that can be used to represent different categories or levels of a variable in a plot. Seaborn provides a wide range of pre-defined color palettes that you can choose from, or you can create your own custom palette.

Using pre-defined color palettes

Seaborn provides several pre-defined color palettes such as “deep”, “muted”, “bright”, “pastel”, and “dark”. These palettes are designed to be visually appealing and well-suited for different types of data.

To use a pre-defined color palette in Seaborn, you can simply pass the palette name as an argument to the set_palette() function. For example, let’s say we want to use the “deep” palette:

import seaborn as sns

# Set the palette to "deep"
sns.set_palette("deep")

This will set the color palette for all subsequent plots created with Seaborn.

Creating custom color palettes

If none of the pre-defined color palettes suit your needs, Seaborn allows you to create custom color palettes. You can specify a custom palette as a list of colors, where each color can be a named color from the matplotlib.colors module, a hex code, or an RGB tuple.

To create a custom color palette, you can use the color_palette() function. Here’s an example that creates a custom palette with three colors:

import seaborn as sns

# Create a custom color palette
custom_palette = sns.color_palette(["#FF0000", "#00FF00", "#0000FF"])

# Set the custom color palette
sns.set_palette(custom_palette)

In this example, we create a custom palette with three colors: red, green, and blue. We then set this custom palette as the default palette for all Seaborn plots.

Conclusion

Seaborn provides a variety of pre-defined color palettes and the flexibility to create custom palettes, allowing you to create visually appealing and informative plots. By choosing the right color palette for your data, you can enhance the understanding and interpretation of your visualizations. So, experiment with different palettes and unleash the full potential of your Seaborn plots!