Skip to main content
Mathematics LibreTexts

11.1: The Plots Package

  • Page ID
  • This page is a draft and is under active development. 

    \( \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}}\)

    There is a relatively simple, but powerful plotting package called Plots and don’t forget to download it as in Appendix XXX. The full documentation is at the Plots.jl website. Recall that once the package is added, enter 

    using Pkg; Pkg.add("Plots")
    using Plots

    The Plots package tries to unify the syntax for plotting anything. The basic command for plotting data or functions in 2D is the plot command, which attempts to plot any object that can be plotted.  The next few examples shows this.

    Plotting Functions

    For plotting a function, simply call plot on the function:



    Note: if you are running this on your own computer, your plot may look a bit different than this one with different fonts. This is mainly due to using a different backend, which is explained below.

    If you want to specify the x-range, try: 

    UndefVarError: plot not defined
     [1] top-level scope at In[1]:1
     [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

    If we want to plot 2 or more functions on the same axes, pass in an array of functions like:


    We will also see below how to change other aspects of the plot including the legend, title, labels on the axes, etc.


    Plot the functions \( f(x) = e^{-x^2}, g(x)=\ln(x) \) on the interval \([-3,3]\)

    # add your code here.


    This page titled 11.1: The Plots Package is shared under a CC BY-SA license and was authored, remixed, and/or curated by Peter Staab.

    • Was this article helpful?