Get startedGet started for free

Plot Attributes and Color Palettes

1. Plot Attributes and Color Palettes

In Plots-dot-jl, customization of plots goes beyond themes. There are multiple approaches to personalize specific attributes of your plots. Let's now explore a variety of those options.

2. Color palettes

We can select the color palette for our plots, which determines the default colors utilized by Plots-dot-jl. Many pre-defined palettes are available; refer to the ColorSchemes-dot-jl documentation page for a comprehensive catalog.

3. Using palettes

Now, let's explore how to incorporate these palettes into our plots. To begin, we set the theme for our plot, choosing the bright theme. Next, we create the desired plot, which in this case is a scatter plot depicting the frequency of respondents' K-Pop listening habits against their age. We utilize the palette argument to select a specific color palette and assign it the desired option, such as Dark2_5. As a result, the plot exhibits a distinct set of pre-defined colors.

4. Plot attributes

Plots-dot-jl provides a plethora of plot attributes. We have covered several attributes in previous videos, such as title, xlabel and ylabel, and color. However, there are many other attributes available to enhance our plots further. Some notable examples include xlims and ylims, which define the bounds for the axes; alpha, which adjusts the opacity of plot elements; linestyle, which determines the style of lines; and markersize and markershape, which control the size and shape of markers. To explore further, the Plots-dot-jl documentation cited below is an excellent starting point.

5. Marker attributes

Now, let's focus on marker attributes. Continuing from our previous example of the scatter plot depicting K-Pop listening habits against the age of survey respondents, we can customize the markers. To achieve this, we can set the markershape argument to diamond while adjusting the markersize argument to the value 8. As a result, the scatter plot will display larger diamond-shaped markers, adding a distinct visual element to the plot.

6. Opacity/Transparency

Considering that the markers in our previous plot overlap, adjusting their opacity or transparency is advisable for better visualization. To accomplish this, we can utilize the alpha argument and assign it a numeric value between zero and one. In this case, let's set it to 0.25. Observe how this adjustment results in a scatter plot where regions with a higher concentration of points appear darker in color. This helps in highlighting areas of increased data density within the plot.

7. Line attributes

Now, let's delve into line attributes. We set the theme to dao and specify a default line width of 4. Next, we generate a normalized histogram depicting the preferred beats per minute of the survey respondents. In addition to the histogram, we incorporate a density plot to visualize the estimated distribution. To modify the density plot's appearance, we can utilize the linestyle argument and set it to dash, resulting in a density plot with a dashed line.

8. Axis bounds and legend attributes

We can also customize the legend and axis bounds displayed in the plot. We give the legend a title and position with the legend_title and legend_position attributes to customize the legend. For the x-axis bounds, we set the xlims function to range from 50 to 230. Observe how this adjustment produces a zoomed-in version of the previous plot.

9. Cheat sheet

Let's end with a cheat sheet for the topics covered in this video, including a list of possible values for the markershape and linestyle attributes.

10. Let's practice!

With an array of tools available, we can precisely control every aspect of our plot's appearance. It's your turn to explore and experiment with this versatile Swiss army knife of customization in the exercises!