5 Data Visualization with Plots.jl

Data visualization is a vital part of almost any data analysis process. For plotting in Julia several options are available, i.e., Plots.jl, Makie.jl and UnicodePlots.jl. Here, in this chapter, we will consider Plots.jl, later we will discuss Makie.jl.

So, what is Plots.jl? Well, it is a visualization interface and toolset used to send plotting instructions to different backends without changing your code for each one of them. Some available backends are for instance GR.jl, PyPlot.jl, PGFPlotsX.jl or Plotly.jl. Note, that each one of them is a package in itself also. Then, if you require full customization it’s recommended to use one of the backends directly. See the official documentation for more information.

Plots.jl will pick a default backend for you automatically based on the ones installed. Usually the default one is GR.jl. Additional requirements are needed on Linux systems. Read the official documentation for more information. When in doubt please refer to the official installation page for Plots.jl.

You should be able to start by simply installing Plots.jl and GR.jl as in:

] add Plots, GR

and then your first plot will be:

using Plots
plot(1:10)
Figure 4: First plot

You can check your current backend by doing:

using Plots: backend

and then simply typing:

backend()
Plots.GRBackend()

and you can switch to another one by doing pyplot() or plotly() for example. Saving a Figure fig is done with savefig(fig, "filename.png"). Simply typing savefig("filename.png") will save the most recent figure. More extensions are also possible for gr, e.g., svg or pdf among others. A complete list for each backend is shown in the Plots.jl’s Output official documentation.

Plots.jl is a well designed package, so that even if you don’t know what you are doing is highly probable that Plots.jl will give you back some output. So, at least when just starting with it, be careful. Later, you can enjoy the power of passing key arguments to plot and create complicated figures with just a few commands. In the next section we will explore these extra arguments, known as Attributes.



DRAFT - CC BY-NC-SA 4.0 Jose Storopoli, Rik Huijzer, Lazaro Alonso