0

Plot XY Graph in Julia Using Data Points

Last Updated on

Plotting numbers in the XY graph in Julia can help us create the big picture. This post shows how to plot data points in a graph using the Plots and GR packages. These data points are our x-y coordinates.

Install Plots And GR Packages In Julia

Before we install these packages, we need to install Julia in our machine. Once installed and configured, start up the Julia interpreter. To install packages, we can either use the Pkg.add() command in the current shell mode or enter package mode. When we are in the current shell mode, we use the following commands in Julia. The Plots package does not need to come first.

Alternatively, we run similar commands in the package mode to install the Plots and GR packages. Note that we need to go back to the shell mode to plot points in the graphs. To enter the package mode, type ] after the julia> prompt.

The package mode prompt replaces the shell mode prompt. Then, we use the commands – add Plots and add GR, as follows.

The Plots package is a visualization interface and toolset where users interact directly by issuing commands together with data points. It wraps the GR package, which is a framework for visualization. The GR package has different types of graphs that we can use. Do we need Plots when we are using GR? It depends. We can use GR without Plots. However, visualization is complicated, but the Plots package makes it easier in Julia.

Plot XY Data Points In Graph

We can now plot some XY data points in a graph and display it. On the Julia command prompt, run the following commands.

Our data points are limited, and we have the same values for both the x-y coordinates. The plot command will display the graph is a separate window, as shown below. It may take a few seconds to display the graph.

Plot XY Graph In Julia

After learning how to plot XY data points in a Graph is Julia, we can now explore other types of graphs with more complex data.

Karl San Gabriel

Karl San Gabriel

Professional Software Developer