How to use sns.set_palette () for Seaborn in Python
This article mainly shows you how to use sns.set_palette() in Seaborn in Python. The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "How to use sns.set_palette() in Seaborn in Python".
sns.set_palette()
This feature is handy if you want to customize the default palette to your favorite color combinations. We can use color mapping in Matplotlib. Here is a selection from the color library. Let's change the palette to "rainbow" and look at the graph again:
#Change default palette sns.set_palette ('rainbow ')#plot plt.figure(figsize=(9, 5))sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', alpha=0.7, hue='species', size='gender')plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1));
If you can't find a Matplotlib color map you like, you can manually select colors to create your own unique palette. One way to create your own palette is to pass a list of color names to a function, as shown in the following example.
#Change default palette sns.set_palette(<$'green ', ' purple','red')#Figure plt.figure(figsize=(9, 5))sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', alpha=0.7, hue='species', size='gender')plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1));
If the color name doesn't capture what you're after well, you can build your own palette using hex colors to access a wider range of options (over 16 million colors!). Here are my favorite resources to find a hex custom palette. Let's look at an example:
#Change default palette sns.set_palette(['#62C370','#FFD166','#EF476F'])#Figure plt.figure(figsize=(9, 5))sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', alpha=0.7, hue='species', size=' gender') plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1)); above is "How to use sns.set_palette() in Seaborn in Python" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!