• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar

Python and R Tips

Learn Data Science with Python and R

  • Home
  • Python
  • Pandas
    • Pandas 101
  • tidyverse
    • tidyverse 101
  • R
  • Linux
  • Conferences
  • Python Books
  • About
    • Privacy Policy
You are here: Home / Python / How to Change Matplotlib Plot’s Style

How to Change Matplotlib Plot’s Style

June 9, 2022 by cmdlinetips

In this post we will learn how to find all available style options for matplotlib plot themes and learn to set a style for matplotlib plot. To illustrate the styling options available in Matplotlib, we will use histogram made from beta distributions.

To get started, let us load the modules needed.

import matplotlib.pyplot as plt
import numpy as np

We can use style or theme options in matplotlib by importing style module from matplotlib.

from matplotlib import style

How to list all available style options in Matplotlib

Matplotlib has 26 different themes or styles available for making plot. If you are interested in finding out all 26 available style options, plt.style.available command will give the names of all available styles as a list.

# get the list of style options in Matplotlib
plt.style.available

['Solarize_Light2',
 '_classic_test_patch',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark',
 'seaborn-dark-palette',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'tableau-colorblind10']

Matplotlib Default Style

When we make plot with Matplotlib, by default it uses default style. Here is an example, three histograms of beta distributions, of a plot with default style.

fig, ax = plt.subplots()
ax.hist(np.random.beta(10, 10, size=1000),
        bins=25, 
        alpha=0.8)
ax.hist(np.random.beta(10, 1, size=1000),
        bins=25, 
        alpha=0.8)
ax.hist(np.random.beta(1, 10, size=1000),
        bins=25, 
        alpha=0.8)
ax.set_title("default Matplotlib style")
plt.savefig("default_matplotlib_style_Python.png",
                    format='png',dpi=150)

Matplotlib Default Plot Style
Matplotlib Default Plot Style

How to set a Matplotlib Style to a plot

We can set a style for plot made with matplotlib using “plt.style.use()” function with the style name of interest. This will change the look or the theme of a plot. For example, to set style to “seaborn-colorblind”, we use the following statement before making the plot.

plt.style.use('seaborn-colorblind')

Let us go ahead and simplify making the histogram using hist() function by wrapping it as a function.

def plot_beta_hist(ax, a, b):
    ax.hist(np.random.beta(a, b, size=1000),
        bins=25, 
        alpha=0.8)

Set Matplotlib PLot Style: Example 1

Now we can use plt.style.use(‘seaborn-colorblind’) to change the style and plot histograms using the above function.

plt.style.use('seaborn-colorblind')
fig, ax = plt.subplots()
plot_beta_hist(ax, 10, 10)
plot_beta_hist(ax, 10, 1)
plot_beta_hist(ax, 1, 10)
ax.set_title("Seaborn colorblind style sheet")
plt.savefig("How_to_set_matplotlib_style_to_Seaborn_colorblind_Python.png",
                    format='png',dpi=150)

We have successfully changed the matplotlib style from default style to colorblind friendly Seaborn-colorblind theme.

How to Change Matplotlib Plot Style to Colorblind friendly?

How to Set Matplotlib Plot Style to Seaborn Colorblind Style

Set Matplotlib Plot Style: Example 2

Similarly, here is another example, where we use ggplot style for a plot made with maptplotlib using “plt.style.use(‘ggplot’)” statement before making the plot.

plt.style.use('ggplot')
fig, ax = plt.subplots()
plot_beta_hist(ax, 10, 10)
plot_beta_hist(ax, 10, 1)
plot_beta_hist(ax, 1, 10)
ax.set_title("ggplot style sheet")
plt.savefig("How_to_set_matplotlib_style_to_ggplot_style_Python.png",
                    format='png',dpi=150)

Our plot made with ggplot style in Matplotlib looks like this.

How to Change Matplotlib Plot Style to ggplot Style
How to Change Matplotlib Plot Style to ggplot grey theme

Note that when we change the plot style, it persists through the session. To reset the plot style, we can use plt.style.use(‘default’).

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related posts:

Colorblind friendly colormap CividisPython’s Matplotlib Version 2.2 is here Seaborn Legend in a row on top of the plotHow to Change the Position of Legend in Seaborn How To Specify Colors to Scatter Plots in Python Overlapping Histograms with Pandas11 Tips to Make Plots with Pandas

Filed Under: Python, Python Tips Tagged With: change Matplotlib plot style, list all matplotlib plot styles

Primary Sidebar

Subscribe to Python and R Tips and Learn Data Science

Learn Pandas in Python and Tidyverse in R

Tags

Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips

RSS RSS

  • How to convert row names to a column in Pandas
  • How to resize an image with PyTorch
  • Fashion-MNIST data from PyTorch
  • Pandas case_when() with multiple examples
  • An Introduction to Statistical Learning: with Applications in Python Is Here
  • 10 Tips to customize ggplot2 title text
  • 8 Plot types with Matplotlib in Python
  • PCA on S&P 500 Stock Return Data
  • Linear Regression with Matrix Decomposition Methods
  • Numpy’s random choice() function

Copyright © 2025 · Lifestyle Pro on Genesis Framework · WordPress · Log in

Go to mobile version