julialangHow to add a legend to a plot in JuliaLang?
Adding a legend to a plot in JuliaLang is easy. The following example code block will add a legend to a plot:
using Plots
x = [1,2,3,4]
y = [2,4,6,8]
plot(x, y, label="Line")
# Add legend
legend()
The code consists of the following parts:
using Plots
: This imports the Plots package.x = [1,2,3,4]
andy = [2,4,6,8]
: These define the x and y coordinates of the plot.plot(x, y, label="Line")
: This creates the plot with the label "Line".legend()
: This adds the legend to the plot.
Helpful links
More of Julialang
- How to test code in JuliaLang?
- How to append to an array in JuliaLang?
- How to use the println function in JuliaLang?
- How to sort in JuliaLang?
- How to use lambda functions in JuliaLang?
- How to work with matrices in JuliaLang?
- How to install JuliaLang on Ubuntu?
- How to install JuliaLang?
- How to measure execution time in JuliaLang?
- How to use the range function in JuliaLang?
See more codes...