How to Reflect the Curve toward $y$ axis with Plots?

Hi all,

I have a code from previous forum, it is a reflection toward x axis, then I want to reflect my curve toward y axis, but I am unable to do so, this is the code:

using Plots, LaTeXStrings, Plots.PlotMeasures

function make_fg_plot()
    g(x) = x^3
    xreflection = x -> -x
    xtransform = xreflection
    plt = plot(; xtick=:false, ylims = (-1, 6), 
	 legend = :topleft, label = "", bottom_margin=10mm)
    for (T, attrs) in [(xtransform, (;label = "", linecolor = :green)), 
                       (identity, (;label = "", linecolor = :green))]
        plot!(plt, T ∘ g, 0, 4; label="") # Plot g and define the interval of existence
    return plt


Capture d’écran_2022-12-28_12-11-45

the reflection of the curve should appear on the left side, looks like x^{2}

Maybe this works (sorry, can’t test right now):

plot!(plt, T.(x), T ∘ g, 0, 4; label="")

I got this:

LoadError: UndefVarError: x not defined

using Plots
plt = plot(;) 
a= π/2
plot!(plt, f, 0, a)
plot!(plt, g, -a, 0)
1 Like

ups, my bad, i thought there is a variable x defined somewhere.

My bad too…

It becomes a great picture now:

using Plots, LaTeXStrings, Plots.PlotMeasures

# For the curve
f(x) = x^3

plt = plot(;xtick=false, xlims=(-2,2), ylims = (0, 5), 
	 legend = :topright, framestyle=:zerolines, label = "", bottom_margin=10mm)
a= π/2

# For the circle
θ = 0:0.1:2π
x1 = 0 .+ 1cos.(θ) 
y1 = 1 .+ 0.33sin.(θ) 
x2 = 0 .+ 0.95cos.(θ) 
y2 = 0.85 .+ 0.33sin.(θ) 
x3 = 0 .+ 1.5cos.(θ) 
y3 = 3.3 .+ 0.33sin.(θ) 

# Plotting time
plot!(plt, f, 0, a, label="")
plot!(plt, g, -a, 0, label="")

plot!(x1, y1, aspect_ratio=:equal, label=L"V = \int_{0}^{3} \pi y^{2/3} \ dy", fill=(0, 0.86, :blue2)) # The middle circle plot
plot!(x2, y2, aspect_ratio=:equal, label="", linecolor=:transparent, fill=(0, 0.23, :blue2)) # The bottom circle plot
plot!(x3, y3, aspect_ratio=:equal, label="") # The top circle plot

Capture d’écran_2022-12-28_15-35-36


There is a better technique, if you extend this line of thought:

Can you think of how to make a scale function that works like the shift function?