julialangHow to create plots in JuliaLang?
Plots in JuliaLang can be created using the Plots.jl package. Plots.jl is a plotting metapackage which brings many different plotting packages under a single API.
using Plots
x = -2π:0.1:2π
y = sin.(x)
plot(x, y, label="sin(x)")
The code above creates a plot of the sine function. The first two lines import the Plots.jl package and create an array of x values. The third line creates an array of y values using the sin function. The fourth line creates the plot using the plot function, which takes the x and y arrays as arguments, and adds a label to the plot.
Code explanation
using Plots
- imports the Plots.jl packagex = -2π:0.1:2π
- creates an array of x valuesy = sin.(x)
- creates an array of y values using the sin functionplot(x, y, label="sin(x)")
- creates the plot using the plot function, which takes the x and y arrays as arguments, and adds a label to the plot
Helpful links
More of Julialang
- How to test code in JuliaLang?
- How to use tuples in JuliaLang?
- How to round numbers in JuliaLang?
- How to append to an array in JuliaLang?
- How to work with matrices in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to use try catch in JuliaLang?
- How to work with CSV in JuliaLang?
- How to create a histogram in JuliaLang?
See more codes...