Line Chart
Two 1-D arrays will be provided as input to the plot() function to plot a simple line chart. Below is the Julia program to plot a Line chart:
Julia
# Julia program to plot a # Line chart # Importing the Module using PyPlot; # Defining the arrays arr = [ 2 , 5 , 6 , 8 ]; arr_2 = arr * 3 ; # Plotting using plot function plot(arr,arr_2); # Providing title to the chart title( "A simple Line Chart" ); # Displaying the chart PyPlot.show(); |
Output:
The graphs can be stylized using various attributes like line color, line width, line style, labels, etc. Some of the attributes are explained below:
Julia
# Julia program to stylize line chart # by changing line width, line color, # line style, labels using PyPlot; arr = [ 2 , 5 , 6 , 8 ]; arr_2 = arr * 3 ; plot(arr, arr_2, linewidth = 5.0 , linestyle = "--" , color = "green" ); title( "A simple Line Chart" ); xlabel( "This is X-Axis" ); ylabel( "This is Y-Axis" ); PyPlot.show(); |
Output:
Attributes:
- linewidth: It defines the width of the line. It only accepts float values.
- linestyle: This is used to define the style of the line we are plotting, there are different styles like ‘:’, ‘-.’, ‘–‘ etc.
- color: It is used to define the color of the line we are plotting.
- labels: This is used to define the labels for the x-axis and y-axis of the plot.
Julia – Working with Matplotlib’s Pyplot Class
Data visualization is the process of representing the available data diagrammatically. There are packages that can be installed to visualize the data in Julia. Here, PyPlot class of the Matplotlib Module in Julia will be used for plotting.
To install the PyPlot package in Julia, the Matplotlib package of Python must be installed on the user’s device. Using the Pkg command we will install PyPlot in Julia Command-Line. Open the Julia terminal and type the following command:
using Pkg;
Pkg.add(“PyPlot”);
Contact Us