如何在Julia的Plots库中创建朝下的花括号?
实现朝下的贝塞尔曲线花括号(Julia Plots)
要让已创建的贝塞尔曲线花括号朝下,无需复杂旋转操作,只需对曲线的y坐标做垂直镜像翻转(围绕目标水平线topy)即可。以下是修改后的完整代码:
using Plots, LaTeXStrings, InverseFunctions gr() x = collect(range(0, 4, length= 100)) f(x) = sqrt(4x) g(x) = (4x - 4)/3 function Area(f, a, b, n) xs = a:(b-a)/n:b deltas = diff(xs) cs = xs[1:end-1] sum(f(cs[i]) * deltas[i] for i in 1:length(deltas)) end r1 = round(Area(y -> (3y + 4 - y^(2))/(4), -1, 4, 50000), digits=5) plot(g,-1,4, xtick=-1:1:4, xlims=(-1,4), ylims=(-2,4), framestyle=:zerolines, label=L"g: 4x - 3y = 4", legend=:topleft) plot!(f,-1,4, xtick=-1:1:4, xlims=(-1,4), ylims=(-2,4), framestyle=:zerolines, label=L"f: y^{2} = 4x ", legend=:topleft) plot!(x, f, fillrange = g, fillalpha = 0.35, c = 1, label = L"f - g = y^{2} - 3y - 4 = 0", legend=:topleft) plot!([0.42,1.95],[f(0.42),g(1.95)], label="", linecolor=:green) plot!([0.3,1.8],[f(0.3),g(1.8)], label="", linecolor=:green) annotate!([(0.27,1.27, (L"△ y", 8, :blue))]) annotate!([(1.95,0.97, (L"y_{i}", 8, :blue))]) annotate!([(2.13,1.17, (L"y_{i+1}", 8, :blue))]) annotate!([(1.41,1.9, (L" \frac{3y+4}{4} - \frac{y^{2}}{4}", 6, :blue))]) # 创建朝下的花括号 topy = 1.5 # 定义垂直镜像翻转函数,围绕topy水平线翻转 flip_y(y) = 2*topy - y # 左半括号:将原朝上的凸起y坐标翻转 bezxl = [0.143239π, 0.143239π, 0.3851545π, 0.3851545π] bezyl = [flip_y(2), topy, flip_y(2), topy] curves!(bezxl, bezyl; linecolor=:blue, label="") # 右半括号:同理翻转y坐标 bezxr = [0.3851545π, 0.3851545π, 0.62707π, 0.62707π] bezyr = [topy, flip_y(2), topy, flip_y(2)] curves!(bezxr, bezyr; linecolor=:blue, label="") # 在Julia REPL中输入r1可查看面积近似值
修改说明:
- 垂直镜像翻转:通过
flip_y(y) = 2*topy - y函数,将原曲线中朝上的凸起(y=2)翻转到topy水平线的下方(y=1),直接实现括号朝下的效果,比旋转操作更精准。 - 简化图例:移除了括号的label,避免图例冗余。
- 坐标对齐:保持x坐标不变,仅调整y坐标,确保括号与原标注的水平线对齐。
内容的提问来源于stack exchange,提问作者Freya the Goddess
相关产品推荐
相关产品推荐

