#xlabel and ylabel trouble

1 messages · Page 1 of 1 (latest)

sinful ruin
#
plotlyjs()

N₁=31 # Number of waveguides / size of solution vector
γ=1  # Nonlinear term strength parameter
h=1 # Grid spacing 

centerGrid  = (N₁-1)/2;
x = -centerGrid:centerGrid;

# Coefficient matrix of second-order centered-difference operator (δ²u)ₙ
M           = spdiagm(-1 => fill(1,N₁-1), 0 => fill(-2,N₁), 1 => fill(1,N₁-1))
M[N₁,1]     = 1; # Periodic boundary conditions
M[1,N₁]     = 1;

# RHS of DNLS. The solution vector u is a N₁x1 complex vector
g₁(u,p,t)   = 1*im*(p[1]*M*u + @.(γ*((abs(u))^2).*u) )

# Julia is explicitly typed (e.g, cannot have Int and Complex in same array) and so we must convert the object containing the initial data to be complex
u0  = Complex.(sech.(x))

tspan = (0.0,200)
prob = ODEProblem(g₁,u0,tspan, [h])
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)

z= [abs(sol.u[i][j])^2  for j=1:N₁, i=1:size(sol)[2]] # |u|²

p1 = surface(sol.t, x, z, xlabel="Time", ylabel="Space", zlabel="|u|²", colorbar = false)
zaxis!("|u|²")
p2 = contourf(sol.t,x,z)
plt = plot(p1,p2,layout=(1,2),xlabel="Time",ylabel="Space", size=(1200,800))

Can someone tell me what I am doing wrong in my label making for my plots? https://i.imgur.com/RglsJSy.png

Where there are "x" and "y" should be "time" and "space" respectively.

unkempt spoke
#

you need to use triple ` followed by the code followed by triple ` in order for the code to show up as a block on discord

sinful ruin
#

keen valve
#

My hunch is that when you used the plot function with xlabel and ylabel, it override the p1 labels, and then expected a list of 2 labels for each of the plots, but because it was just a single value, it applied it to the 2nd plot for some reason. I'd try either passing in a list of labels or put the xlabel ylabel in the p2 assignment, with plot having none of those

#

It's only a hunch because I'm confused why it would only apply to the 2nd plot rather than the first

unkempt spoke
#

dzon is suggesting

p1 = surface(sol.t, x, z, xlabel="Time", ylabel="Space", zlabel="|u|²", colorbar = false)
p2 = contourf(sol.t,x,z, xlabel="Time", ylabel="Space")
plt = plot(p1,p2,layout=(1,2), size=(1200,800))
keen valve
#

Yeah sorry I was gonna test it until the cat asked for attention, anyway Clemonthyme got the right idea and running it I get this

#

(I just did a random y and z value)

#

Hmm, I get the same result if I did this julia p1 = surface(1:10, y, z; colorbar=false) p2 = contourf(1:10, y, z) plt = plot(p1, p2; layout=(1,2), size=(1200,800), xlabel="Time", ylabel="Space", zlabel="|u|²")

#

Maybe it's because I defined zlabel or something

#

Removing zlabel, I would just get time and space labelled on both graphs with nothing as the zlabel

#

Wait I just remembered you used plotly so lemme check that

unkempt spoke
#

I think specifying zlabel explicitely for p1 necessitates also explicitly specifying xlabel and ylabel for p1

#

your last code isn't equivalent since p2 shouldn't have a zlabel at all

#

so just put the labels into p1 and p2 definitions and not put any labels in the final plot plt

keen valve
#

The result is equivalent though

#

I think that the plot function figures it out or plotly has plot.jl integrations problems

keen valve
#

Plotly JS just doesn't work on my system

keen valve
#

Nevermind I think my internet dropped out and did weird stuff

#

Or something to do with concurrency errors related to WebIO

#

Running it on 1 thread makes the 2 charts overlap each other

unkempt spoke
#

wat

#

that's pretty funny actually

keen valve
sinful ruin