# How to plot a mirror graph from the one created

**URL:** <https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [January 5, 2024, 4:25pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394 "2024-01-05T16:25:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 4:25pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/1 "2024-01-05T16:25:09Z")

</div>

Hi does anyone know how to plot my already plotted graph by mirroring it on the negative value?

 ![nozz_page-0001](https://global.discourse-cdn.com/julialang/original/3X/f/4/f4d33f447e8ae6056033e467e09669833cf5f483.jpeg)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 5, 2024, 4:56pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/2 "2024-01-05T16:56:53Z")

</div>

I’m not sure if I understand your question. Mirroring? Over which axis? What do you mean by “negative value”?

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 5:04pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/3 "2024-01-05T17:04:09Z")

</div>

i meant by with the same plot but mirrroring it on the negative value so that i can get a cone shape in the end over the x axis

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 5, 2024, 5:25pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/4 "2024-01-05T17:25:11Z")

</div>

If you plotted some data `x, y`, why not just plot `[-reverse(x); x], [reverse(y); y]` instead — i.e. the same data but with the mirror image appended?

For example:

```julia
using Plots

x = range(0, 3, length=1000)
y = @. x^2 + 1

p1 = plot(x,y)
p2 = plot([-reverse(x); x], [reverse(y); y])
plot(p1, p2)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/c/9/c9a45200f878701bbfaf717471027e71cb41efaf.png)

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 6:24pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/5 "2024-01-05T18:24:45Z")

</div>

i have plotted the graph its looking better unfortunately there is a connecting line with it how do i remove it?

fyi this is what im currently working with and there is a lot of variables:

```julia
function f(x; θ=15*pi/180)
    if (x>-R1*sin(θ)) && (x<R1*sin(θ))
        (R_throat+R1*(1-cos(asin(x/R1))))
    elseif (x>R1*sind(θ))
        (m*x+Y0)
    end
end

using Plots

x=range(0, Xe, length=100)
y=m .* x .+Y0
p1=plot((x,f.(x, θ=15*pi/180)), ylims=(0,0.75))
p2=plot([reverse(x); x], [-reverse(y); y])

```

 ![plot_2_page-0001](https://global.discourse-cdn.com/julialang/original/3X/e/5/e55e594feb49e8b63ab319b7f941111ec81b444f.jpeg)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 5, 2024, 6:53pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/6 "2024-01-05T18:53:28Z")

</div>

> [@kim1](#):
>
> i have plotted the graph its looking better unfortunately there is a connecting line with it how do i remove it?

Plot two separate curves for the two lines (i.e. two separate `plot!` calls).

PS. I edited your post to [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530).

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 7:11pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/7 "2024-01-05T19:11:52Z")

</div>

this what i got after using the plot!

```
 function f(x; θ=15*pi/180)
    if (x>-R1*sin(θ)) && (x<R1*sin(θ))
        (R_throat+R1*(1-cos(asin(x/R1))))
    elseif (x>R1*sind(θ))
        (m*x+Y0)
    end
end

using Plots

x=range(0, Xe, length=100)
y=m .* x .+Y0
p1=plot((x,f.(x, θ=15*pi/180)), ylims=(0,0.75))
p2=plot([reverse(x); x], [-reverse(y); y])
plot!(p1, p2)

```

 ![plot_3_page-0001](https://global.discourse-cdn.com/julialang/original/3X/1/e/1e84e5a98e0c00cbfd5224039e979645d8100720.jpeg)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 5, 2024, 7:18pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/8 "2024-01-05T19:18:05Z")

</div>

> [@kim1](#):
>
> this what i got after using the plot!

No, I mean something like:

```julia
plot(x, y, color="blue")
plot!(reverse(x), -reverse(y), color="blue")

```

![image](https://global.discourse-cdn.com/julialang/original/3X/7/a/7af66eb13db8214f6b0d76d94c40c2d3aafdd30d.png)

PS. Your posted code is not runnable because you didn’t include all of the parameters. I just picked some values at random. [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

PPS. Beware of the habit of using global variables like `R1` in your functions. Not only are [globals problematic for software engineering](https://www.google.com/search?q=global+variables+bad) in general, they typically [lead to slow code](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables) in Julia.

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 7:30pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/9 "2024-01-05T19:30:47Z")

</div>

I dont know why but it didnt worked just gonna share my whole code 😂

```julia
P0=15
P0_pa=1519875
p_amb=101325
R=8314
Rspec=R/Molar_mass
Cp=2112
Cv=Cp-Rspec
γ=Cp/Cv
Pe=0.372
Thrust_exit=450000
T0=2500
Te=(Pe/P0)^((γ-1)/γ)*T0
Me=sqrt((2/(γ-1))*((P0/Pe)^((γ-1)/γ)-1))
Ae=sqrt(γ*Rspec*Te)
Ue=Me*Ae
ṁ=Thrust_exit/Ue
ρ=(Molar_mass*P0_pa)/(R*T0)
A_star=ṁ/(ρ*((2/(γ+1))^(1/(γ-1)))*sqrt(γ*Rspec*(2/(γ+1))*T0))
A_ratio=A_star*sqrt((1/Me^2)*((2/(γ+1))*(1+((γ-1)/2)*(Me^2)))^((γ+1)/(γ-1)))
a_star=sqrt(γ*Rspec*T0*(2/(γ+1)))

θ=15*pi/180
R_throat=sqrt(A_star/pi)
R1=1.5*R_throat
ϵ=A_ratio/A_star
Re=sqrt(ϵ)*R_throat
Rn=R_throat+R1*(1-cos(θ))
λ=(1+cos(θ))/2 
Ln=(Re-R_throat+R1*(cos(θ)-1))/tan(θ)
L=(R_throat*(sqrt(ϵ)-1)+R1*(cos(θ)-1))/tan(θ)+(R1*sin(θ))
L1=L-Ln
τ=(λ*ṁ*Ue)+(Pe-p_amb)*A_ratio
Xn=R1*sin(θ)
Yn=R_throat+R1*(1-cos(θ))
Xe=Xn+Ln
Ye=Re+R1*(1-cos(θ))
m=(Ye-Yn)/(Xe-Xn)
Y0=(-m*Xn)+Yn

    function f(x; θ=15*pi/180)
        if (x>-R1*sin(θ)) && (x<R1*sin(θ))
            (R_throat+R1*(1-cos(asin(x/R1))))
        elseif (x>R1*sind(θ))
            (m*x+Y0)
        end
    end

    using Plots

    x=range(0, Xe, length=100)
    y=m .* x .+Y0
    p1=plot((x,f.(x, θ=15*pi/180)), ylims=(0,0.75), color="blue")
    p2=plot!([reverse(x); x], [-reverse(y); y], color="blue")

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 5, 2024, 7:34pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/10 "2024-01-05T19:34:53Z")

</div>

> [@kim1](#):
>
> `p2=plot!([reverse(x); x], [-reverse(y); y], color="blue")`

You’re still not doing what I suggested … you’re doing the same thing as you did before (a single plot call with both the data and the reversed data), so it’s not surprising that you get the same results.

You’re still not quoting your code with backticks as explained in the links … and you’re not making an effort to give a _minimal_ runnable example as explained in steps 4–5 of [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

You need to put a little more effort into your question (and into thinking about this on your own) if you want to get much more help.

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 5, 2024, 8:19pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/11 "2024-01-05T20:19:52Z")

</div>

Alright Im sorry already read the steps for the backticks but now when I input the new code as suggested it comes out as error.

```julia
plot!(reverse(x,f.(x, θ=15*pi/180)), -reverse(ylims=(0,0.75), color="blue"))

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 5, 2024, 8:48pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/12 "2024-01-05T20:48:48Z")

</div>

> [@kim1](#):
>
> `reverse(x,f.(x, θ=15*pi/180)),`

This is not at all what I suggested [above](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/8) — it seems almost like you are trying syntax at random? You need to spend a little time learning what functions like [`reverse`](https://docs.julialang.org/en/v1/base/arrays/#Base.reverse-Tuple%7BAbstractVector%7D) actually do before using them.

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 6, 2024, 5:51pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/13 "2024-01-06T17:51:32Z")

</div>

After multiple tries this is the result I gotten.

```julia
    x=range(0, Xe, length=100)
    y=m .* x .+Y0
    plot((x,f.(x, θ=15*pi/180)), ylims=(0,0.75), color="blue")
    plot!(reverse(x)), -reverse(y), color="blue")

```

 ![plot 4_page-0001](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce9c26dccbf2db398e377573fae6c2ff1b279077.jpeg)

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 8, 2024, 3:21pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/14 "2024-01-08T15:21:51Z")

</div>

You are plotting different y values in the `plot()` call vs the `plot!()` call which explains why your plot is not symmetric.

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 8, 2024, 6:59pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/15 "2024-01-08T18:59:56Z")

</div>

Yeah when I tried to do the y value its comes out as error.

```julia
plot!(reverse(x)), -reverse(ylims=(0,0.75)), color="blue")

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 8, 2024, 7:09pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/16 "2024-01-08T19:09:19Z")

</div>

> [@kim1](#):
>
> `reverse(ylims=(0,0.75))`

this won’t work!

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 8, 2024, 7:12pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/17 "2024-01-08T19:12:14Z")

</div>

Do you have any suggestion what should i do?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 8, 2024, 7:22pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/18 "2024-01-08T19:22:28Z")

</div>

Another way of doing this is to insert NaN’s in the data vector to break the plot line:

```julia
using Plots
f(x) = x .^ 1.2
x = range(0.2, 1.5, 100)
y = f.(x)
plot([-x; NaN; x], [y; NaN; y], ylims=(0, 0.75), c=:blue)

```

 ![Plot_Symmetric](https://global.discourse-cdn.com/julialang/original/3X/4/a/4a3cf18a98e42fa9d985feefdca1c7b7e1caad39.png)

---

<div class="post-metadata">

**Author:** ![kim1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim1/32/205937_2.png) [@kim1](https://discourse.julialang.org/u/kim1)\
**Post date:** [January 8, 2024, 7:52pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/19 "2024-01-08T19:52:23Z")

</div>

I have tried NaN but i comes out differently than what im trying to achieve. I have drawn the ideal graph that i wanted to achieve. [above] is the curve([How to plot a mirror graph from the one created](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394))

```julia
    function f(x; θ=15*pi/180)
        if (x>-R1*sin(θ)) && (x<R1*sin(θ))
            (R_throat+R1*(1-cos(asin(x/R1))))
        elseif (x>R1*sind(θ))
            (m*x+Y0)
        end
    end

    using Plots

    x=range(0, Xe, length=100)
    y=m .* x .+Y0
    plot([-x; NaN; x], [y; NaN; y], ylims=(0,0.75), color="blue")

```

 ![plot_15_page-0001](https://global.discourse-cdn.com/julialang/original/3X/f/8/f8cada221ae4f3b4e40824bd6eff8e48481a7a4e.jpeg)  
 ![ideal](https://global.discourse-cdn.com/julialang/original/3X/8/5/8503c59ba9cba467998658119653089b1ba3d3de.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 8, 2024, 8:09pm UTC](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394/20 "2024-01-08T20:09:25Z")

</div>

```julia
y = f.(x)
plot(x,y)
plot!(x,-y)

```

My `f` is different from yours, so the curve is different, but here’s my plot:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/8/28e4dfbad24a1a44544ec2fc64dfa83c9260894c.png)

[Next page](https://discourse.julialang.org/t/how-to-plot-a-mirror-graph-from-the-one-created/108394.md?page=2)
