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

**URL:** <https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 28, 2022, 5:12am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209 "2022-12-28T05:12:10Z")\
**Posts on this page:** 8\
**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 28, 2022, 5:12am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/1 "2022-12-28T05:12:10Z")

</div>

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:

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

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
    end
    return plt
end

make_fg_plot()

```

![Capture d’écran_2022-12-28_12-11-45](https://global.discourse-cdn.com/julialang/original/3X/0/e/0eda11c8335c50161d1b567d75510fd960ad4c6c.png)

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

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [December 28, 2022, 8:00am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/2 "2022-12-28T08:00:41Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> `plot!(plt, T ∘ g, 0, 4; label="")`

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

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

```

---

<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 28, 2022, 8:08am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/3 "2022-12-28T08:08:10Z")

</div>

I got this:

**LoadError: UndefVarError: x not defined**

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [December 28, 2022, 8:09am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/4 "2022-12-28T08:09:22Z")

</div>

```julia
using Plots
f(x)=sin(x)
g(x)=f(-x)
plt = plot(;) 
a= π/2
plot!(plt, f, 0, a)
plot!(plt, g, -a, 0)

```

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [December 28, 2022, 8:18am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/5 "2022-12-28T08:18:58Z")

</div>

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

---

<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 28, 2022, 8:35am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/6 "2022-12-28T08:35:56Z")

</div>

My bad too…

---

<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 28, 2022, 8:36am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/7 "2022-12-28T08:36:24Z")

</div>

It becomes a great picture now:

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

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

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

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 28, 2022, 9:15am UTC](https://discourse.julialang.org/t/how-to-reflect-the-curve-toward-y-axis-with-plots/92209/8 "2022-12-28T09:15:23Z")

</div>

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

> [@How to Transform Plots / Shape with Plots.jl](https://discourse.julialang.org/t/how-to-transform-plots-shape-with-plots-jl/92079/7):
>
> It’s not even really specific to the y yy -axis, and using built-in partial application types makes it play nice with things like InverseFunctions.jl:
> 
> ```julia
> shift(ν) = Base.Fix1(+, ν)
> shift(5) ∘ f # y-up-shift
> f ∘ shift(2) # x-left-shift
> 
> ```

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