Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

11.1: The Plots Package

This page is a draft and is under active development. 

( \newcommand{\kernel}{\mathrm{null}\,}\)

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 

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

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

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

using 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:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

plot(x->x^2)
plot(x->x^2)
 

 

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: 

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

plot(x->x^2,-2,2)
plot(x->x^2,-2,2)
UndefVarError: plot not defined

Stacktrace:
 [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:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

plot([x->x^2,x->sin(x)],-2,2)
plot([x->x^2,x->sin(x)],-2,2)
 

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

Exercise

Plot the functions f(x)=ex2,g(x)=ln(x) on the interval [3,3]

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

# add your code here.
# 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.

Support Center

How can we help?