# Setting xlim and ylim in PlotlyJS

I want to change the x and y limits in PlotlyJS. I run this examplecode in Julia 0.5.2:

``````import PlotlyJS
x = linspace(0, 10, 200)
y = sin.(x)
PlotlyJS.plot(PlotlyJS.scatter(x=x, y=y))
``````

and I’ve tried multiple ways of adding x and y limits but none have worked. How do I set the limits on the axis?

`xaxis_range=[0.75, 5.25]`

Where shall I put it?

`plot(scatter(x = x, y = y), Layout( xaxis_range=[0.75, 5.25]))`

I am not super familiar with PlotlyJS as I tend to use it through Plots, but they separate the plotlevel attributes from the serieslevel attributes by putting the plotlevel attributes in a Layout object.

Thank you! This solution works for my first example, in 2D, but when I try examples where I plot in 3D it’s not working. For example:

``````N = 32
u = linspace(0, 2π, N)
v = linspace(0, π, N)
x = cos(u) * sin(v)'
y = sin(u) * sin(v)'
z = repeat(cos(v)',outer=[N, 1])

using PlotlyJS
PlotlyJS.plot(PlotlyJS.surface(x=x,y=y,z=z),Layout(xaxis_range=[0,5]))
``````

How come this doesn’t change the x-limits? How can I do instead?

I finally found the solution. Apparently you have to add `scene_xaxis_range=[0,5]` instead of just `xaxis_range=[0,5]` when using 3D plots. I don’t know why it differs but at least it works!

1 Like