# Introducing Julia/Plotting
## Plotting

There are a number of different packages for plotting in Julia, and there's probably one to suit your needs and tastes. This section is a quick introduction to one of them, Plots.jl, which is interesting because it talks to many of the other plotting packages. Before making plots with Julia, download and install the first plotting package or any or all to choose from (to get the prompt press ]):
The first package, Plots, is a high-level plotting package that interfaces with other plotting packages, which here are referred to as 'back-ends'. They act as the graphics "engines" that produce the graphics. Each of these is also a stand-alone plotting package, and can be used separately, but the advantage of using Plots as the interface is, as you'll see, a simpler and consistent interface.
See also the powerful Makie.jl, which is unrelated to Plots.jl, and has its own backends, such as GLMakie.jl, and many extensions such as AlgebraOfGraphics.jl (these are not explained more in the article, except for this installation example):
You can start using the Plots.jl package in a Julia session in the usual way:
You usually want to plot one or more series, arrays of numerical values. Alternatively, you can provide one or more functions to generate numerical values.
In this example, we'll plot the phases (illuminated fractions) of the moon for the month of May, 2022.
We now have an array of Float64 values, one for each hour of the month, representing how much of the moon's disk is illuminated:
To plot these series, just pass them to Plots' plot function.
This has used the first available plotting engine (GR.jl). Plots has added other plotting "furniture" and then plotted everything for you.
If you want to switch to a different engine, use one of the provided functions: gr, unicodeplots, plotly, and so on. For example, to switch to using the Unicodeplots plotting package (which uses Unicode characters to make plots, and is ideal for use in the REPL/terminal), do this:

## Customizing plots

There is copious documentation for the Plots.jl package, and after studying it you'll be able to spend hours tweaking and customizing your plots to your heart's content. Here's just one example of a plot of the equation of time for every day in a year.
The ticks along the x-axis are the numbers from 1:365. It would be better to see the dates themselves. First, create the strings:
The supplied value for the xticks option is a tuple consisting of two arrays/ranges:
the first provides the numerical values, the second provides matching text labels for the ticks.
Extra labels and legends are easily added. You can access colors from the Colors.jl package:

## Other packages
### UnicodePlots

If you work in the REPL a lot, perhaps you want a quick and easy way to draw plots that use text rather than graphics for output? The UnicodePlots.jl package uses Unicode characters to draw various plots, avoiding the need to load various graphic libraries. It can produce:
* scatter plots
* line plots
* bar plots (horizontal)
* staircase plots
* histograms (horizontal)
* sparsity patterns
* density plots
Download and add it to your Julia installation, if you haven't already done so:
You have to do this just once. Now you load the module and import the functions:
Here is a quick example of a line plot:
And here's a density plot:
(Note that it needs the terminal environment for the displayed graphs to be 100% successful - when you copy and paste, some of the magic is lost.)

### VegaLite

allows you to create visualizations in a web browser window. VegaLite is a visualization grammar, a declarative format for creating and saving visualization designs. With VegaLite you can describe data visualizations in a JSON format, and generate interactive views using either HTML5 Canvas or SVG. You can produce:
* Area plots
* Bar plots/Histograms
* Line plots
* Scatter plots
* Pie/Donut charts
* Waterfall charts
* Wordclouds
To use VegaLite, first add the package to your Julia installation. You have to do this just once:
Here's how to create a stacked area plot.
A general feature of VegaLite is that you can modify a visualization after you've created it. So, let's change the color scheme using a function (notice the "!" to indicate that the arguments are modified):
You can create pie (and donut) charts easily by supplying two arrays. The x array provides the labels, the y array provides the quantities: