Get startedGet started for free

Getting started with Plots.jl

1. Getting started with Plots.jl

Now that we recognize the importance of data visualization for understanding the data we work with, it's time to roll up our sleeves and explore Plots-dot-jl - a powerful and flexible plotting library in Julia.

2. Plots.jl

With Plots-dot-jl, we can create a wide range of plots with a unified interface, making it a go-to tool for many data analysts and scientists. So let's dive in and start plotting with Plots-dot-jl!

3. Installing and importing Plots.jl

To use Plots-dot-jl, we first need to install it. To do this, we'll use Julia's package manager, Pkg. Once Pkg is imported, we can install Plots-dot-jl with the add command. After Plots-dot-jl is installed, we can import it into our code.

4. Our first Julia plot

Let's go ahead and create our first Julia plot. To start, we must import several packages: CSV and DataFrames-dot-jl for loading the dataset and Plots-dot-jl for creating the plot. We can then load the dataset from a dot-csv file into a DataFrame named fund, containing the ETF fund data discussed at the beginning of this chapter. We can use the plot function to create a line plot to visualize the data. We use as arguments the price date and open price columns as the x- and y-axis variables, respectively, allowing us to see the fund's opening price fluctuations over time.

5. From lines to points

While line plots are well-suited for tracking changes in a variable over time, scatter plots are more effective for visualizing the relationships between variables. Let's explore the relationship between daily opening and closing prices. We import the necessary packages again and load the fund dataset from a dot-csv file. To create a scatter plot, we call the scatter function with the open and close columns as arguments. Notice how closely these variables are related to each other.

6. Adding title and axis labels

To improve the readability of our plot, we need to add a clear and descriptive title and labels for the x and y axes. To achieve that, we only need to pass additional arguments to the scatter function. As before, the first two arguments are the open and close columns of the fund data frame. To add a title to the plot, we can set the title argument to a string that accurately describes the nature of the plot and the data we are visualizing. Additionally, by setting the xlabel and ylabel arguments, we can add informative labels to the x and y axes. That will help the reader better understand the relationship between the displayed variables. With these additions, our plot has become much more effective in conveying insights about the relationship between the opening and closing prices.

7. Cheat Sheet

In this video, we created a line plot to visualize how a variable varies over time and a scatter plot to explore the relationship between variables. By adding clear and descriptive titles and axis labels, we learned how to improve the readability of our plot.

8. Let's practice!

Great work! We explored the Plots-dot-jl library, a powerful tool for data visualization in Julia. Now, it's your turn to apply what you learned in the exercises coming next!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.