Officially recommended Plots

Simple drawing

using Plots
y = rand(20,1)
plot(y,linewidth=2,title="My Plot")


Plots with portfolio composition can draw pictures with a small amount of code and rich content, but it seems that it is not currently supported in the Julia v1.0 version. After the support is supported, a tutorial on drawing with Plots will be made.

Fast drawing tool GR

GR is relatively fast, generally you can choose to use GR when drawing some simple graphs.

Draw a simple sine curve, add a title and label

using GR
x = 0:0.1:100
y = sin.(x)
xlim([0, 120])
ylim([-1.5, 1.5])
xlabel("time")
ylabel("sin-value")
title("sin-plot")
plot(x, y)


Draw 4 curves in one graph, add label

x = 1:0.1:100
y1 = sin.(x)
y2 = 2*sin.(2 .* x)
y3 = 3*sin.(3 .* x)
y4 = 4*sin.(4 .* x)
y = [y1 y2 y3 y4]
legend("sinx", "sin2x", "sin3x", "sin4x")
xlabel("x")
ylabel("y")
xlim([0, 100])
ylim([-4.5, 4.5])
title("rand-plot")
plot(x, y[:,1], "r",
x, y[:,2], "g",
x, y[:,3], "b",
x, y[:,4], "black")


Plot the bessel function

using SpecialFunctions
x = collect(0:0.01:20)
legend("0 order", "1 order", "2 order", "3 order")
title("Bessel function")
title("Bessel function")
xlim([0, 20])
ylim([-1, 1])
plot(x, SpecialFunctions.besselj.(0, x),
x, SpecialFunctions.besselj.(1, x),
x, SpecialFunctions.besselj.(2, x),
x, SpecialFunctions.besselj.(3, x))


Scatter plot

n = 500
x = rand(n)
y = rand(n)
title("rand scatter")
scatter(x, y)


using Gadfly
plot(x=rand(10), y=rand(10))

plot(x=rand(10), y=rand(10), Geom.point, Geom.line)

plot(x=1:10, y=rand(10).^2,
Scale.y_sqrt, Geom.point, Geom.smooth,
Guide.xlabel("Stimulus"), Guide.ylabel("Response"), Guide.title("Dog Training"))


Draw two curves in one plot

plot([sin, cos], 0, 25)


PyPlot

One-dimensional data

using PyPlot
y = rand(20)
x = 1:20
# pygui(true)
plot(x, y, lw=2.0, linestyle="--")
grid(true)
axis("tight")
xlabel("index")
ylabel("value")
title("A simple plot1")


Set line color

y = rand(20)
x = 1:20
# pygui(true)
plot(x, y, lw=2.0, color="r", linestyle="--")
grid(true)
axis("tight")
xlabel("index")
ylabel("value")
title("A simple plot1")


Two-dimensional data

y = rand(20,2)
x = 1:20
using PyPlot
# pygui(true)
plot(x, y[:,1], lw=2.0, label="1st", color="r", linestyle="--")
plot(x, y[:,2], lw=1.5, label="2nd", color="b", linestyle="-")
grid(true)
legend(loc=0)
axis("tight")
xlabel("index")
ylabel("value")
title("A simple plot2")


Multiple subgraphs

y = rand(20,2)
x = 1:20
# pygui(true)
subplot(211)
plot(y[:,1], lw=1.5, label="1st")
grid(true)
axis("tight")
xlabel("index")
ylabel("y[1]")
title("The first plot")
subplot(212)
plot(y[:,2], lw=1.5, label="1st")
grid(true)
axis("tight")
xlabel("index")
ylabel("y[2]")
title("The second plot")


Cabinet diagram

y = rand(10,4)
boxplot(y)
xlabel("x")
ylabel("y")
title("boxplot")
# show()

Reference: https://cloud.tencent.com/developer/article/1653098 7 Julia Drawing Tools-Cloud + Community-Tencent Cloud