Setting xlim and ylim in PlotlyJS


#1

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?


#2

xaxis_range=[0.75, 5.25]


#3

Where shall I put it?


#4

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.


#5

Thank you! :slight_smile:


#6

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?


#7

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!