O'Reilly logo

IPython Interactive Computing and Visualization Cookbook - Second Edition by Cyrille Rossant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Matplotlib styles

Recent versions of Matplotlib have significantly improved the default style of its figures. Today, Matplotlib comes with a set of high-quality predefined styles along with a styling system that lets one customize all aspects of these styles.

How to do it...

  1. Let's import the libraries:
    >>> import numpy as np
        import matplotlib as mpl
        import matplotlib.pyplot as plt
        %matplotlib inline
  2. Let's see a list of all available styles:
    >>> sorted(mpl.style.available)
    ['bmh',
     'classic',
     'dark_background',
     'fivethirtyeight',
     'ggplot',
     'grayscale',
     'mycustomstyle',
     'seaborn',
     ...
     'seaborn-whitegrid']
  3. We create a plot:
    >>> def doplot(): fig, ax = plt.subplots(1, 1, figsize=(5, 5)) t = np.linspace(-2 * np.pi, 2 * np.pi, 1000) x = np.linspace(0, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required