11.1: The Plots Package
This page is a draft and is under active development.
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
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:
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.
Exercise
Plot the functions \( f(x) = e^{-x^2}, g(x)=\ln(x) \) on the interval \([-3,3]\)