Skip to main content
Mathematics LibreTexts

42.1: Matplotlib

  • Page ID
    70553
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    We will be using the matplotlib library quite a bit to visualize the concepts in this course. This is a very big library with a lot of components. Here are some basics to get you started.

    First, in order to see the figures generated by the matplotlib library in a jupyter notebook you will need to add the following like to a code cell somewhere near the top of the notebook. This like of code must run before any figures will display.

    %matplotlib inline

    Next, we typically we import either the pylab or pyplot packages from the matplotlib library using one of the following import statements. In most cases these statements are interchangeable, however, in this class we will generally stick to using pyplot because it has a little more functionality.

    import matplotlib.pylab as plt

    or

    import matplotlib.pyplot as plt

    The basic way to plot values is to use the plot function as follows:

    y = [0,1,4,9,16,25,36]
    plt.plot(y);

    The matplotlib library is big!!! There is no way we can cover all of the topics in this notebook. However, it is not that hard to use and there are plenty of tutorials and examples on the Internet.

    Do This

    Review the matplotlib examples in the Matplotlib Example Gallery.


    This page titled 42.1: Matplotlib is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?