如何在带有绘图的 Julia 中创建大括号?

How to Create a Curly Brackets in Julia with Plots?

提问人:Freya the Goddess 提问时间:12/22/2022 最后编辑:Freya the Goddess 更新时间:12/26/2022 访问量:267

问:

我想创建一个这样的括号:

image

我目前使用一条线和两条杠来替换支架,我尝试使用带有旋转的 } 并增加长度,但它不起作用。

这是我的代码:

using Plots, LaTeXStrings
gr()

x = collect(range(0, 4, length= 100))
f(x) = sqrt(4x)
g(x) = (4x - 4)/3

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))])

plot!([0.45,1.97],[1.5,1.5], label="", linecolor=:blue)
annotate!(0.45,1.5, Plots.text("|", 10, :blue, rotation = 0 ))
annotate!(1.97,1.5, Plots.text("|", 10, :blue, rotation = 0 ))

annotate!([(1.41,1.7, (L" \frac{3y+4}{4} - \frac{y^{2}}{4}", 6, :blue))])

编辑: 我能够在贝塞尔曲线的帮助下制作卷曲的支架,只剩下小东西,如何将其旋转 180 度以使其面朝下?


using Plots
gr()

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))])

#plot!([0.45,1.97],[1.5,1.5], label="", linecolor=:blue)
#annotate!(0.45,1.5, Plots.text("|", 10, :blue, rotation = 0 ))
#annotate!(1.97,1.5, Plots.text("|", 10, :blue, rotation = 0 ))

annotate!([(1.41,1.9, (L" \frac{3y+4}{4} - \frac{y^{2}}{4}", 6, :blue))])

# Create curly bracket
topy = 1.5

# Left bracket starting from 0.143239π, and ending at the middle at 0.3851545π 
bezxl = [0.143239π, 0.143239π, 0.3851545π, 0.3851545π] 
bezyl = [2, topy, 2, topy]
curves!(bezxl, bezyl; linecolor=:blue, label="left")

# Right bracket starting from the middle at 0.3851545π and end at 0.62707π
bezxr = [0.3851545π, 0.3851545π, 0.62707π, 0.62707π]
bezyr = [topy, 2, topy, 2]
curves!(bezxr, bezyr; linecolor=:blue, label="right")

# Type at julia REPL after finish to gain the area' approximation: r1

current progress

朱莉娅

评论


答:

3赞 Stepan Zakharov 12/23/2022 #1

对不起

using Plots

plot(sin; xlim=(0, 2π))

topy = 0.4

bezxl = [π/2, π/2, π, π]
bezyl = [0, topy, 0, topy]
curves!(bezxl, bezyl; label="left")

bezxr = [π, π, 3π/2, 3π/2]
bezyr = [topy, 0, topy, 0]
curves!(bezxr, bezyr; label="right")

上面的示例使用贝塞尔曲线

enter image description here

还有我发现的......

免责声明:我的微观研究(实际上是谷歌搜索)并没有假装是完整和正确的。

  • 似乎 Plots.jl 的文本类型与 Shape 类型不兼容。对于后者,有转换工具。我会想象什么时候我们可以说“沿 y 轴缩放文本,然后旋转”。例如,据我所知,在 R 中,这是可能的
  • 一个疯狂的想法是找到一种字体,其中大括号符号的行高和宽度根据需要不成比例......
  • 所以,我想到的下一个想法是绘制一个看起来像大括号的函数......
  • 这是大括号绘制的 matlab 实现。似乎,作者将其定义为部分功能。
  • 此外,我还发现了一个 reddit 帖子,有人通过大括号找到了 2d 镶嵌的方程式。
  • 毕竟,我记得有贝塞尔曲线。希望 Plots.jl 支持他们。

评论

0赞 Freya the Goddess 12/26/2022
不用抱歉,每个人都会犯错/罪过。哈哈。谢谢你,贝塞尔曲线?多么好的解决方案......Bezier Curve 的起源是在一辆漂亮的汽车中创造一条曲线。
0赞 Freya the Goddess 12/26/2022
你的代码效果很好,我修改了一下,现在只需要把它颠倒过来。
0赞 Freya the Goddess 12/29/2022
完成,关键是玩如果它高于数字,否则它将朝下,否则它将朝上topybezylbezyr