Get startedGet started for free

Customizing with themes

1. Customizing with themes

To effectively display data and convey insights through our plots, it is crucial to customize them appropriately. Let's embark on our journey into customization in this video.

2. Plots.jl themes

The easiest method to alter the appearance of our plot is by applying a theme. Themes enable us to modify multiple customization options simultaneously. To select a theme, we utilize the theme function from Plots-dot-jl. The initial argument is a symbol representing the desired theme. Plots-dot-jl offers many options, including dark, ggplot2, juno, and the default theme. We can also pass additional keyword arguments, which include all of the attributes we encounter in the previous chapters and many more. For instance, when calling the theme function, we can select the juno theme while customizing the default line color and width using the linecolor and linewidth arguments.

3. Previewing themes

To get a preview of a specific theme, we can utilize the showtheme function from the Plots package. This function generates a series of plots with the chosen theme, allowing us to explore its effects visually.

4. Favorite music genres

Let's observe plot theming in action through a concrete example. Here, we will work with a dataset that examines the impact of music on various mental health conditions. Firstly, we load this dataset from a CSV file. Next, we'll determine the favorite genres of the survey respondents. To accomplish this, we group the DataFrame by favorite genre and employ the combine function to count the number of rows for each genre. As we've discovered in this course, bar charts are an excellent method for visualizing counts of categorical variables. So, let's create one!

5. Default-themed bar chart

We use the bar function to generate a bar chart, providing the favorite genre, and count columns as arguments. Additionally, we can customize the chart by hiding the legend and setting a title and y-axis label. Since we didn't specify a theme before creating this chart, Plots-dot-jl applies its default theme.

6. Try a different theme

Now, let's experiment with a different theme. To do this, we need to call the theme function before creating our bar chart and pass the desired theme (in this case, juno) as the argument. Creating the bar chart remains the same as before. No changes are needed to create a plot with a different theme. Notice how it appears very distinct from the previous chart!

7. Make it pop!

We can pass additional arguments to the theme function to set default attributes. For instance, we specify a default line color and width by providing the linecolor and linewidth arguments. Moreover, we can hide the axis lines by setting the framestyle argument to grid. By incorporating these modifications, we can generate a striking bar chart that effectively communicates information in a visually appealing manner! It would be a pity to lose such a striking plot. Let's save it by using the savefig function! To accomplish this, we provide the filename or path as an argument to the savefig function.

8. Let's practice!

The most effective approach to becoming skilled at customizing plots is through practice. So, have fun exploring and creating captivating plots during your exercises!