How to plot a mirror graph from the one created

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

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

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

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:

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

2 Likes

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:

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 two separate curves for the two lines (i.e. two separate plot! calls).

PS. I edited your post to quote your code.

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)

No, I mean something like:

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

image

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

PPS. Beware of the habit of using global variables like R1 in your functions. Not only are globals problematic for software engineering in general, they typically lead to slow code in Julia.

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

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
ṁ=Thrust_exit/Ue
ρ=(Molar_mass*P0_pa)/(R*T0)
A_star=ṁ/(ρ*((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
τ=(λ*ṁ*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")

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

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.

2 Likes

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.

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

This is not at all what I suggested above — it seems almost like you are trying syntax at random? You need to spend a little time learning what functions like reverse actually do before using them.

1 Like

After multiple tries this is the result I gotten.

    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")

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

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

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

this won’t work!

Do you have any suggestion what should i do?

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

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)

1 Like

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)

    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")


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:

2 Likes