# Keeping a consistent perspective for 3D plots

**URL:** <https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692>\
**Category:** Plotly R\
**Created:** [September 8, 2017, 3:12am UTC](https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692 "2017-09-08T03:12:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![significance](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@significance](https://community.plotly.com/u/significance)\
**Post date:** [September 8, 2017, 3:12am UTC](https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692/1 "2017-09-08T03:12:53Z")

</div>

I am trying to animate a large 3D scatter plot. Because the vectors involved are large, it is too slow to render if I use plotly’s built-in animation capability, so instead, I am saving each frame as a PNG file and using another tool to do the animation.  
I am having some trouble with the perspective bouncing around between frames, even though I am using the same scene (including camera “up”, “center” and “eye” and axis information) and the same x and y values for each frame. Hence, most of my frames look like this:

 ![A100001](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/2/299c4926739bda71c9ab256345e848c78134a31f.png)

But for a few frames, it zooms in for no apparent reason and it looks like this:

 ![A100005](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/3e71a9dd4fa0ac0125029fe9a35290b1abf55c09.png)

(In case you are curious, this is simulated ocean colour and surface elevation overlaying a map from ggmap().

Is there anything I can do to stop it from zooming in and out?

Here’s my code:

> ```
> eye <- list(x = 0.065, y =-1.625, z = 0.2925)
> scene = list(camera = list(up = list(x=0, y=0, z=1), 
> center=list(x=0, y=0, z=0),
> eye = eye),
> xaxis = list(range = c(142.1688, 157),
> title="",
> showline=FALSE,
> showticklabels=FALSE,
> showline=FALSE,
> showgrid=FALSE),
> yaxis = list(range = c(-28.7, -7.01),
> title="",
> showline=FALSE,
> showticklabels=FALSE,
> showline=FALSE,
> showgrid=FALSE),
> zaxis = list(range = c(-2.4,8),
> title="",
> showline=FALSE,
> showticklabels=FALSE,
> showline=FALSE,
> showgrid=FALSE),
> showlegend = FALSE
> )
> 
> for (i in 1:dim(z)[3]) { 
> 
> p <- plot_ly(x=x,
> y=y,
> z=c(z[,,i]),
> type="scatter3d",
> mode="markers",
> marker=list(color=c(truecolor[,,i]), size=2, alpha=0.5),
> showlegend=FALSE) %>%
> layout(scene = scene)
> 
> p <- add_trace(p, x=mapx, 
> y=mapy, 
> z= - 2.4,
> type="scatter3d",
> mode="markers",
> marker=list(color=mapcolor, size=2),
> showlegend=FALSE) 
> 
> fname <- paste0('elev_movie/A', 100000 + i, '.png', collapse='')
> plotly_IMAGE(p, format="png", out_file=fname)
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [September 8, 2017, 9:49am UTC](https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692/2 "2017-09-08T09:49:52Z")

</div>

Hey there,

To prevent this behaviour set in `xaxis`, `yaxis`, `zaxis`, autorange=False.

---

<div class="post-metadata">

**Author:** ![significance](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@significance](https://community.plotly.com/u/significance)\
**Post date:** [September 8, 2017, 11:12pm UTC](https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692/3 "2017-09-08T23:12:01Z")

</div>

Thank you – I really appreciate the help. I’ve just tried it, but unfortunately, setting autorange=FALSE for xaxis, yaxis and zaxis didn’t make any difference. To clarify: the axes aren’t changing between images, just the perspective.

---

<div class="post-metadata">

**Author:** ![significance](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@significance](https://community.plotly.com/u/significance)\
**Post date:** [September 9, 2017, 12:15am UTC](https://community.plotly.com/t/keeping-a-consistent-perspective-for-3d-plots/5692/4 "2017-09-09T00:15:12Z")

</div>

Update: I’ve partially fixed the problem by the enormous kludge of adding a “ghost” trace (a scatter3d trace with alpha=0.00005) of one of the troublesome frames to every other frame – see below for the results – but I’d still like to learn how to do this properly. I am sure there is something simple that I am missing!

 ![elev_movie2](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/1f291991b361b14c6b0c7c8c341331691bb73aa9.gif)
