# Setting xlim and ylim in PlotlyJS

**URL:** <https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386>\
**Category:** New to Julia\
**Created:** [August 15, 2017, 1:46pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386 "2017-08-15T13:46:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 15, 2017, 1:46pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/1 "2017-08-15T13:46:06Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 15, 2017, 1:59pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/2 "2017-08-15T13:59:19Z")

</div>

`xaxis_range=[0.75, 5.25]`

---

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 15, 2017, 2:04pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/3 "2017-08-15T14:04:35Z")

</div>

Where shall I put it?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 15, 2017, 2:35pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/4 "2017-08-15T14:35:33Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 15, 2017, 3:01pm UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/5 "2017-08-15T15:01:41Z")

</div>

Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 16, 2017, 6:33am UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/6 "2017-08-16T06:33:51Z")

</div>

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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 16, 2017, 11:57am UTC](https://discourse.julialang.org/t/setting-xlim-and-ylim-in-plotlyjs/5386/7 "2017-08-16T11:57:52Z")

</div>

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!
