Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to find the matplotlib style name?
Matplotlib provides several built-in styles to customize the appearance of your plots. To find all available matplotlib style names, you can use the plt.style.library attribute which returns a dictionary containing all available styles and their configurations.
Using plt.style.library
The plt.style.library returns a dictionary where keys are style names and values are their complete configuration parameters ?
import matplotlib.pyplot as plt print(plt.style.library)
{'bmh': RcParams({'axes.edgecolor': '#bcbcbc',
'axes.facecolor': '#eeeeee',
'axes.grid': True,
'axes.labelsize': 'large',
'axes.prop_cycle': cycler('color', ['#348ABD', '#A60628', '#7A68A6', '#467821', '#D55E00', '#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2']),
'axes.titlesize': 'x-large',
'grid.color': '#b2b2b2',
'grid.linestyle': '--',
'grid.linewidth': 0.5,
...}),
'classic': RcParams({'_internal.classic_mode': True,
'agg.path.chunksize': 0,
'animation.bitrate': -1,
...}),
'seaborn-v0_8': RcParams({'axes.axisbelow': True,
'axes.edgecolor': '#f0f0f0',
'axes.facecolor': '#f0f0f0',
'axes.grid': True,
...})}
Getting Only Style Names
If you only want the style names without their configuration details, you can extract the dictionary keys ?
import matplotlib.pyplot as plt
# Get only the style names
style_names = list(plt.style.library.keys())
print("Available styles:")
for style in style_names:
print(f" - {style}")
Available styles: - bmh - classic - dark_background - fast - fivethirtyeight - ggplot - grayscale - seaborn-v0_8 - seaborn-v0_8-bright - seaborn-v0_8-colorblind - seaborn-v0_8-dark - seaborn-v0_8-dark-palette - seaborn-v0_8-darkgrid - seaborn-v0_8-deep - seaborn-v0_8-muted - seaborn-v0_8-notebook - seaborn-v0_8-paper - seaborn-v0_8-pastel - seaborn-v0_8-poster - seaborn-v0_8-talk - seaborn-v0_8-ticks - seaborn-v0_8-white - seaborn-v0_8-whitegrid - Solarize_Light2 - tableau-colorblind10 - _classic_test_patch
Using plt.style.available
Alternatively, you can use plt.style.available which directly returns a list of available style names ?
import matplotlib.pyplot as plt
print("Available matplotlib styles:")
print(plt.style.available)
Available matplotlib styles: ['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test_patch']
Conclusion
Use plt.style.available to get a clean list of style names, or plt.style.library to access both style names and their complete configuration parameters. These styles can be applied using plt.style.use('style_name') to customize your plot appearance.
