43  画图

43.1 正弦图

using Plots
gr() # 使用GR作为绘图后端,也可以选择其他后端,比如pyplot()

x = range(0, stop=2π, length=100) # 生成 x 值
y = sin.(x) # 计算对应的 y 值,这里使用了 Julia 的广播(broadcasting)特性

plot(x, y, label="sin(x)", xlabel="x", ylabel="sin(x)", title="Sine Function", lw=2)

43.2 Parametric Plots

Plot function pair (x(u), y(u)). See 图 43.1 for an example.

using Plots

plot(sin, 
     x->sin(2x), 
     0, 
     2π, 
     leg=false, 
     fill=(0,:lavender))
图 43.1— Parametric Plots