There is a relatively simple, but powerful plotting package called Plots and don’t forget to download it as in Appendix B. The full documentation is at the Plots.jl website. Recall that once the package is added, enter 1
This function often takes a while to load due to some precompiling. Also, the first time a plot is created, it’ll take a while. The julia team knows this is a problem and calls is the TTFP or time to first plot problem.
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. The idea call plot on any type of object that can be plotted. The next few examples shows this.
Note: 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.
where the legend is turned off, since with one curve, it doesn’t make much sense. The result is \begin{center} \pgfplotsset{scale=0.7} \plot{plots/plots/parametric01.tex}{plots} \end{center}
but notice that this should be a circle, but it looks like an ellipse due to the aspect ratio. If one instead adds the \verb!aspect_ratio=:equal! option, as in
An implicit curve is the set of points such that \(f(x,y)=0\) (or any constant) and a circle is the classic example. The curve below is the set of all points such that \(x^2+y^2=1\text{.}\) It can be plotted in Julia with the following command.
Note that again, we have used the \verb!aspect_ratio = :equal! to ensure that the circle looks like a circle. The resulting plot is exactly the same as the circle above.
We can extend this notion to any function of two variables, say \(f(x,y)\) and plot many implicit curves together for different constants. That is plots of the form \(f(x,y)=c\) for multiple \(c\) values and this is called a contour plot. The following is \(x^2+y^2=c\) for \(c=1,4,9,16\) which creates 4 concentric circles.
If we have a function of 2 variables, a surface plot is nice to use. For example, if we have the function \(f(x,y)=e^{-(x^2+y^2)/10}\) and we want to plot it from -3 to 3 in both directions, if we define
where x and y were defined above for the scatter plot. The result is \begin{center} \pgfplotsset{scale=0.7} \plot{plots/plots/bar01.tex}{plots} \end{center}
This just is the tip of the iceberg for plotting. Take a look at the Plots.jl documentation or do some google-foo with the phrase `Plots.jl’ and what you’re looking for and good spot for Q & A is a julialang.org discourse site
Use the plotting techniques in this section to plot the following. For each, hide the legend when ther e is only one curve/set of data and label appropriate if more than one curve/set of data. Include a title as well.
The Plots.jl package actually doesn’t do the plotting. It leaves the details to other packages. By default, Plots uses the GR backend although in this text I have used the PGFPlotsX backend which tends to print nicer. There are a number of backends that you may want to try. The standard ones are:
To switch the backend, you type the backend name in all lowercase with a set of (). Note: you will need to add and load the package. Here is the plot of \(x^2\) on various backends.
Subsection15.5.1Changing the attributes of the plot
Let’s return back to the function plots above (although this works for point/line plots as well) and change many attributes of the curve. As an example:
Take the scatterplot above (with the random dots) and change the color of the dots to darkgreen, change the markers to diamonds and the size of the points to about twice the default size.