27rohitb.github.io

Plotting

NOTE:

Import plots:

using Plots  #import package

Specify backend:

gr()  #faster backend

Plot command:

plot(x,y, label="linear", legend=:topleft, xaxis="x", yaxis=("y", :log), dpi=200)

# FOR MUTIPLE PLOT:
plot!(x2, y2, dpi=200)

Insert axis:

xaxis!("x [-]")
yaxis!("f(x) [-]")

Add title:

title!("polynomial")

Add anotation:

Anotation = text on the graph:

anotate!(x, y, Plots.text("This will appear at x,y", 5, :red) )

Save plot:

savefig("<filename>.<extension>")

Scatter plot:

scatter(x, y, yerr=yerr, markersize=2, markershape=:o, alpha0.5, label="data")

Subplots:

Example:

# Make a plot and modify it to add another plot on the same.
p1 = scatter(x,y)
p1 = plot!(x2,y2)

# Make another plot and modify it as well:
p2 = scatter(x3,y3)
p2 = plot!(x4, y4)

# PLOT THEM ALL
plot(p1, p2, layout=(2,1), dpi=200)

Pylot from Julia

Much faster !!!!

using package:

using PyPLot

plot command:

julia
plot(x,y, color="red", linewidth=2.0, linestyle="--")

Add title:

title("A sin wave")