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

**URL:** <https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181>\
**Category:** General Usage\
**Tags:** plotting, math\
**Created:** [December 27, 2022, 9:52am UTC](https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181 "2022-12-27T09:52:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 27, 2022, 9:52am UTC](https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181/1 "2022-12-27T09:52:47Z")

</div>

Hi all,

I have created the left side of the picture:

![Capture d’écran_2022-12-27_16-49-32](https://global.discourse-cdn.com/julialang/original/3X/a/b/ab4d09a1ed36bce49c70e71c500e795ef9eabf95.png)

with this code:

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/5/3/53bfc49a9853c34afa290db247aab297a79e35f9.png)

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.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [December 27, 2022, 10:30am UTC](https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181/2 "2022-12-27T10:30:15Z")

</div>

Maybe take a look at:

> **[Gabriel's Horn - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/gabriels_horn/)**
>
> Makie Examples

> **[Revolution surface - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/revolution_surface/)**
>
> Makie Examples

> **[Revolution surface s - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/revolution_surface_s/)**
>
> Makie Examples

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

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 27, 2022, 3:12pm UTC](https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181/3 "2022-12-27T15:12:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 27, 2022, 3:12pm UTC](https://discourse.julialang.org/t/how-to-create-bone-of-cylinder-with-ellipse-with-plots-plotlyjs/92181/4 "2022-12-27T15:12:41Z")

</div>

Meanwhile I have created the plot by patchwork:

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e0fd5d1176d9580c116eff6c15dcda4699bc22e.png)
