1. Series Recipes
Since we have become experts in customization, let's discover ways to prevent redundant tasks and create reusable plotting recipes for future use!
2. Customizing a plot
Let's start by creating an impressive-looking violin plot using what we've learned.
We invoke the violin function to plot the insomnia column against the favorite genre column from the streaming DataFrame. We hide the legend and all lines.
Next, we customize the violin's fill properties by specifying a fill color and alpha.
We then use the permute argument to interchange the x and y axes.
Lastly, we hide the grid lines.
The outcome is a captivating violin plot. Wouldn't it be great to save and reuse these instructions for future reference?
3. Plots.jl series
Before proceeding further, it's essential to grasp a significant concept in Plots-dot-jl, known as series.
A series is a set of data points that are plotted similarly. For instance, when using the plot function with a single line of data, the data is interpreted as a series of line type.
Plots-dot-jl offers various series types, including line, scatter, and more, each tailored for specific plotting needs.
A single plot can contain multiple series. For example, when we use the scatter function with two vectors on the y-axis, it generates two series of type scatter, with each column representing a distinct series.
Plots-dot-jl employs series recipes to handle data plotting for different series types.
Moreover, we have the flexibility to design custom recipes, allowing us to tailor the appearance of our series precisely to our preferences within our plots.
4. It's all plot in the end
Let's illustrate this with a revisited example.
Instead of using the violin function, we will use the plot function with the same arguments.
However, this time, we explicitly specify the seriestype argument as violin.
By doing so, we generate an identical plot as we did previously with the violin function.
5. Custom series recipes
Recipes are a predefined set of instructions that dictate how to create a specific type of data visualization. Let's now create a recipe to preserve the customization we just constructed.
We begin by defining and prefixing a plotting function with the @recipe notation. The function's first argument follows the format double colon, type, val, followed by a symbol representing the series recipe name. In our case, we'll use my_hviolin to denote our customized horizontal violin plot.
The subsequent three arguments correspond to the x, y, and z series data.
Inside the function body, we first set the series type as violin.
Next, we list all the customization options we desire for our recipe. We don't use commas to separate these options; we write each one a new separate line instead. Each option should be assigned using a colon and an equal sign instead of just an equal sign. The same is true when setting the series type.
6. Using custom series recipe
Using the recipe we crafted is straightforward. Simply assign the name of our custom recipe to the seriestype argument when calling the plot function.
Observe how easily we can now reuse our recipe!
7. Using custom series recipe
Simplifying the reuse of a recipe becomes even more convenient with the help of the @shorthands notation, which allows us to define a custom plotting function for our recipe.
Once the my_hviolin function is defined, we can use it just like any other standard Plots-dot-jl function.
This convenience is truly remarkable!
8. Same recipe, different data
We can now effortlessly plot different data in the same format. For instance, we can utilize the my_hviolin function to plot the OCD or anxiety columns instead of the insomnia column.
9. Plot recipes
Plots-dot-jl offers various recipes, including plot recipes that support multiple series in a single plot. For more in-depth information, refer to the documentation.
10. Let's practice!
Let's expand our recipe book in the exercises by including some new recipes!