Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Matplotlib

Eitan Lees
September 27, 2019

 Matplotlib

An introduction to the python visualization library Matplotlib

Eitan Lees

September 27, 2019
Tweet

More Decks by Eitan Lees

Other Decks in Research

Transcript

  1. View Slide

  2. Nicolas P. Rougier:
    - Researcher in computational cognitive neuroscience, located in
    Bordeaux, France
    - Inria (the French institute for computer science)
    - Institute of Neurodegenerative Diseases
    - Author of several scientific computing books (All Free!)
    - Python & OpenGL for Scientific Visualization
    - From Python to Numpy
    - Scipy Lecture Notes
    Jake VanderPlas:
    - Visiting Researcher Google Seattle Office
    - Former Director of Open Software at the University of
    Washington’s eScience institute
    - Contributions made in
    - Scikit-Learn
    - SciPy
    - AstroPy
    - Altair

    View Slide

  3. View Slide

  4. Part One:
    The Origin Story

    View Slide

  5. Matplotlib was created by John D. Hunter in 2003 to
    visualize electrocorticography data. In a post to the official
    python mailing list John writes ...
    My goal is to make high quality,
    publication quality plotting easy
    in python, with a syntax familiar
    to matlab users.

    View Slide

  6. Matplotlib was created by John D. Hunter in 2003 to
    visualize electrocorticography data. In a post to the official
    python mailing list John writes ...
    My goal is to make high quality,
    publication quality plotting easy
    in python, with a syntax familiar
    to matlab users.
    Also motivated later in the post ...
    * make easy things easy
    (subplots, lines styles, colors)
    * make hard things possible
    (OO interface for full control)

    View Slide

  7. Matplotlib Development Timeline

    View Slide

  8. The Python Visualization Landscape

    View Slide

  9. Important Questions:
    - Do you target desktop or web rendering?
    - Do you need complex 3D rendering?
    - Do you need publication quality?
    - Do you have very large data?
    - Is there an active community?
    - Are there documentation and tutorials?

    View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. Strengths:
    - Designed like MatLab: switching was easy

    View Slide

  14. Strengths:
    - Designed like MatLab: switching was easy
    - Many rendering backends

    View Slide

  15. Strengths:
    - Designed like MatLab: switching was easy
    - Many rendering backends
    - Can reproduce just about any plot (with a bit of effort)

    View Slide

  16. Strengths:
    - Designed like MatLab: switching was easy
    - Many rendering backends
    - Can reproduce just about any plot (with a bit of effort)
    - Well-tested, standard tool for over a decade

    View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. Strengths:
    - Designed like MatLab: switching was easy
    - Many rendering backends
    - Can reproduce just about any plot (with a bit of effort)
    - Well-tested, standard tool for over a decade
    Weaknesses:
    - API is imperative & often overly verbose
    - Poor support for web/interactive graphics
    - Often slow for large & complicated data

    View Slide

  21. Part Two: The Tale of Two API’s

    View Slide

  22. Matplotlib is
    organized in a
    hierarchy.

    View Slide

  23. Matplotlib is
    organized in a
    hierarchy.
    At the top of the hierarchy is the matplotlib "state-machine
    environment" which is provided by the
    matplotlib.pyplot module. At this level, simple
    functions are used to add plot elements (lines, images, text,
    etc.) to the current axes in the current figure.

    View Slide

  24. Matplotlib is
    organized in a
    hierarchy.
    At the top of the hierarchy is the matplotlib "state-machine
    environment" which is provided by the
    matplotlib.pyplot module. At this level, simple
    functions are used to add plot elements (lines, images, text,
    etc.) to the current axes in the current figure.
    The next level down in the hierarchy is the first level of the
    object-oriented interface. At this level, the user uses pyplot
    to create figures, and axes objects which are then used for
    most plotting actions.

    View Slide

  25. Matplotlib is
    organized in a
    hierarchy.
    At the top of the hierarchy is the matplotlib "state-machine
    environment" which is provided by the
    matplotlib.pyplot module. At this level, simple
    functions are used to add plot elements (lines, images, text,
    etc.) to the current axes in the current figure.
    The next level down in the hierarchy is the first level of the
    object-oriented interface. At this level, the user uses pyplot
    to create figures, and axes objects which are then used for
    most plotting actions.
    At the lowest level matplotlib manages a variety of graphics
    primitives and engines to render and display figures.

    View Slide

  26. MATLAB-style
    Interface
    Object-Oriented
    Interface

    View Slide

  27. MATLAB-style
    Interface
    Object-Oriented
    Interface
    plt.plot(x, y)
    plt.xlim(-1, 1)
    plt.title(“My Plot”)
    ...

    View Slide

  28. MATLAB-style
    Interface
    Object-Oriented
    Interface
    plt.plot(x, y)
    plt.xlim(-1, 1)
    plt.title(“My Plot”)
    ...
    fig = plt.figure()
    ax = fig.add_axes([0.1,0.1,0.8,0.8])
    ax.plot(x, y)
    ax.set(xlim=(-1, 1), title=”My Plot”)
    ...

    View Slide

  29. Fast and
    Convenient
    Detailed and
    Powerful
    plt.plot(x, y)
    plt.xlim(-1, 1)
    plt.title(“My Plot”)
    ...
    fig = plt.figure()
    ax = fig.add_axes([0.1,0.1,0.8,0.8])
    ax.plot(x, y)
    ax.set(xlim=(-1, 1), title=”My Plot”)
    ...

    View Slide

  30. MATLAB-style
    Interface
    Object-Oriented
    Interface
    plt.gcf() or plt.gca()

    View Slide

  31. Demo
    Time

    View Slide

  32. View Slide

  33. View Slide