How to Create Bone of Cylinder with Ellipse with Plots / PlotlyJS?

Hi all,

I have created the left side of the picture:

Capture d’écran_2022-12-27_16-49-32

with this code:

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = sqrt(x)

plot(f,0,4, xtick=0:4:4, xlims=(0,6), ylims=(0,3), 
	framestyle=:zerolines, bottom_margin=5mm,
	label=L"y = \sqrt{x}", legend=:topright)

plot!(f,0,5, label="", fill=(0, 0.15, :blue))
plot!(f,2,2.3, label="", fill=(0, 0.35, :blue))

# Annotations
annotate!([(2.12,1.6, (L"△ x", 8, :blue))])
annotate!([(2,-0.1, (L"x_{i}", 8, :blue))])
annotate!([(2.4,-0.1, (L"x_{i+1}", 8, :blue))])

ch1-calculus-6applicationsoftheintegral-18

Now I want to know how to create the right side of the picture? Because it seems to be complex, need to erase the vertical line of the \sqrt{x} at x=4 and replace with ellipse, and another ellipse in the middle with fill.

Maybe take a look at:

they generate parametric plots in 3d. Just like you example above.

1 Like

Yes, but parametric equations is in later chapter of Calculus, I am not ready to learn them. But I will read this Makie for 3d plots.

Meanwhile I have created the plot by patchwork:

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

function make_fg_plot()
    g(x) = sqrt(x)
	
    yshift = y -> y 
    yreflection = y -> -y
    ytransform = yshift ∘ yreflection
    #  To plot a circle of radius 1 centered at (1.6, 0) 
    θ = 0:0.1:2π
    x1 = 1.6 .+ 0.5cos.(θ) 
    y1 = 0 .+ 1.23sin.(θ) 
    x2 = 1.4 .+ 0.5cos.(θ) 
    y2 = 0 .+ 1.2sin.(θ) 
    x3 = 4 .+ 0.7cos.(θ) 
    y3 = 0 .+ 1.97sin.(θ) 
    
    plt = plot(; xtick=:false, ylims = (-3, 3), 
	 legend = :topleft, label = "", bottom_margin=10mm)
    for (T, attrs) in [(identity, (;label = "", linecolor = :green)), 
                       (ytransform, (;label = "", linecolor = :red))]
        #plot!(plt, T ∘ f, 0, 4; label="") # Plot f and define the interval of existence 
        plot!(plt, T ∘ g, 0, 4; label="") # Plot g and define the interval of existence
        plot!(x1, y1, aspect_ratio=:equal, label="", fill=(0, 0.15, :blue2)) # The middle circle plot
	plot!(x2, y2, aspect_ratio=:equal, label="", fill=(0, 0.17, :blue2)) # The left circle plot
	plot!(x3, y3, aspect_ratio=:equal, label="", fill=(0, 0.05, :blue2)) # The right circle plot
    end
    return plt
end

make_fg_plot()

Capture d’écran_2022-12-27_22-10-24