- Seaborn Tutorial
- Seaborn - Home
- Seaborn - Introduction
- Seaborn - Environment Setup
- Importing Datasets and Libraries
- Seaborn - Figure Aesthetic
- Seaborn- Color Palette
- Seaborn - Histogram
- Seaborn - Kernel Density Estimates
- Visualizing Pairwise Relationship
- Seaborn - Plotting Categorical Data
- Distribution of Observations
- Seaborn - Statistical Estimation
- Seaborn - Plotting Wide Form Data
- Multi Panel Categorical Plots
- Seaborn - Linear Relationships
- Seaborn - Facet Grid
- Seaborn - Pair Grid
- Function Reference
- Seaborn - Function Reference
- Seaborn Useful Resources
- Seaborn - Quick Guide
- Seaborn - Useful Resources
- Seaborn - Discussion
Seaborn.mpl_palette() method
The Seaborn.mpl_palette() method is used such that a matplotlib palette's discrete color values are returned.
Although you will receive less colors than you anticipated if you request more colors than a given qualitative palette can provide, this method manages the qualitative color brewer palettes correctly. Contrarily, using color palette() to request qualitative color brewer palettes will provide the anticipated number of colors, but they will cycle.
For continuous palettes, discrete samples that are evenly spread, excluding the minimum and maximum value in the colormap, are chosen to provide better contrast at the extremes.
Syntax
Following is the syntax of the mpl_palette() method –
seaborn.mpl_palette(name, n_colors=6, as_cmap=False)
Parameters
The parameters of this method are seen below.
S.No | Parameter and Description |
---|---|
1 | N_colors Takes integer values that determines the number of discrete color sin the palette. |
2 | name Takes string values and is the name of the palette. This palette should typically be a matplotlib colormap. |
Return Value
This method returns a list of RGB tuples or a matplotlib colormap.
Example 1
In this example we will see how to use the mpl_palette method. We will have to use the palplot method available in seaborn to produce a series of colors that belong to a particular palette using this mpl_palette method. This mpl_palette() method returns a matplotlib colormap. The palplot() method can be omitted if not desired.
import seaborn as sns import matplotlib.pyplot as plt data = sns.palplot(sns.mpl_palette("gist_rainbow", 12)) sns.palplot(data) plt.show()
Output
The output obtained is as follows −
Example 2
We will see other palettes in this method. In this example, we will produce a colomap with only the mpl_palette() method and not using the palplot() method.
import seaborn as sns import matplotlib.pyplot as plt data = sns.mpl_palette("inferno", 12) sns.palplot(data) plt.show()
Output
The output is as follows −
Example 3
We will see the list of all the palettes that can be used in this method and along wihtt hat we will also see another palette the colors it contains.
'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'crest', 'crest_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'flare', 'flare_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'icefire', 'icefire_r', 'inferno', 'inferno_r', 'jet', 'jet_r'
The above mentioned names are some of the colors that are part of the seaborn color paleters and all these inbuilt seaborn palettes can be used to produce colros as per as our wish and need. Another palette is shown below.
sns.mpl_palette("gist_earth", 12)
Output
The output is as follows −
To Continue Learning Please Login
Login with Google