2

I want to create a bracket like this:

image

I currently use a line and two bars to replace the bracket, I try to use } with rotation and increase the length and it is not working.

this is my code:

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

Edited: I am able to make the curly bracket with the help of the Bezier Curve, only small thing left, how to rotate it 180 degree so it will face to bottom?


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

1 Answers1

3

Sorry for that

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

The example above uses Bezier curves.

enter image description here

Also what I've found...

Disclaimer: My micro-research (googling, actually) does not pretend to be complete and correct.

  • Seems like textual type of Plots.jl isn't compatible with Shape type. For the latter there are transforming tools. I'd imagine when sometime we can say "scale text along y axis, then rotate". E.g., in R, as I understand, it's possible.
  • One crazy idea is to find a typeface, where line height and width of curly brace symbol is disproportional as needed...
  • So, the next idea came to my mind is to plot a function that looks like curly brace...
  • Here is a matlab implementation of curly brace drawing. Seems like, the author defines it as partial function.
  • Also I've found a reddit post where someone find equation for 2d tessellation by curly braces.
  • After all, I remembered that there are Bezier curves. Hopefully, Plots.jl supports them.
Stepan Zakharov
  • 547
  • 2
  • 11