# PlotlyJS doesn't implement orthographic projection option

**URL:** https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203
**Category:** Visualization
**Tags:** plots, 3d, plotlyjs
**Created:** [March 16, 2023, 7:03pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203 "2023-03-16T19:03:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bhalpin](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bhalpin](https://discourse.julialang.org/u/bhalpin)
#### Post date: [March 16, 2023, 7:03pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/1 "2023-03-16T19:03:00Z")

</div>

PlotlyJS has an option for orthographic projection rather than the default “perspective” projection. It is described in the docs here:

[https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/](https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/)

The orthographic example is actually using perspective.

The options work as intended with GR.

Code to reproduce (based on the example in the docs):

```plaintext
x = [[-1, 1], [-1, -1], [-1, 1], [1, 1], [1, 1], [-1, -1], [-1, -1], [1, 1], [-1, 1], [-1, -1], [-1, 1], [1, 1]]
y = [[1, 1], [-1, 1], [-1, -1], [-1, 1], [1, 1], [1, 1], [-1, -1], [-1, -1], [1, 1], [-1, 1], [-1, -1], [-1, 1]]
z = [[1, 1], [1, 1], [1, 1], [1, 1], [-1, 1], [-1, 1], [-1, 1], [-1, 1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]
kw = (aspect_ratio = :equal, label = :none, xlabel = "x", ylabel = "y", zlabel = "z", xlims = (-1.1, 1.1), ylims = (-1.1, 1.1), zlims = (-1.1, 1.1))

plotlyjs()

plot(plot(x, y, z; proj_type = :ortho, title = "PlotlyJS incorrect ortho", camera = (45, round(atand(1 / √2); digits = 3)), kw...),
     plot(x, y, z; proj_type = :persp, title = "PlotlyJS perspective", camera = (45, round(atand(1 / √2); digits = 3)), kw...))

gr()

plot(plot(x, y, z; proj_type = :ortho, title = "GR correct orthographic", camera = (45, round(atand(1 / √2); digits = 3)), kw...),
     plot(x, y, z; proj_type = :persp, title = "GR perspective", camera = (45, round(atand(1 / √2); digits = 3)), kw...))

```

(Am trying to figure out how to add graphics files…)

In the absence of graphics, the orthogonal projection of a cube at this angle should yield a regular hexagon, whereas perspective projection yields a hexagon that is appropriately distorted. PlotlyJS produces similar irregular hexagons for both cases, whereas GR does it right.

---

<div class="post-metadata">

### Author: ![bhalpin](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bhalpin](https://discourse.julialang.org/u/bhalpin)
#### Post date: [March 16, 2023, 10:45pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/2 "2023-03-16T22:45:02Z")

</div>

The GR docs and the PlotlyJS docs on the issue show the problem clearly

[https://docs.juliaplots.org/stable/gallery/gr/generated/gr-ref060/#gr\_ref060](https://docs.juliaplots.org/stable/gallery/gr/generated/gr-ref060/#gr_ref060)

vs

[https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/](https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/)

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [March 16, 2023, 11:10pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/3 "2023-03-16T23:10:10Z")

</div>

Using direct PlotlyJS, not via Plots, the two projections are distinct:  
 ![perspective](https://global.discourse-cdn.com/julialang/original/3X/8/c/8ce2368e58b219d19cb8965bd0908199e1793465.png)  
 ![orthographic](https://global.discourse-cdn.com/julialang/original/3X/b/6/b666b8bf3e1e0e4278320cb3d0af5b9a029d827e.png)

---

<div class="post-metadata">

### Author: ![bhalpin](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bhalpin](https://discourse.julialang.org/u/bhalpin)
#### Post date: [March 17, 2023, 7:27pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/4 "2023-03-17T19:27:01Z")

</div>

OK, that helps localise the problem. Thanks!

Could you please show how to do that? I can plot using PlotlyJS without Plots, but I can’t figure out how to pass the projection parameter.

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [March 17, 2023, 10:31pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/5 "2023-03-17T22:31:28Z")

</div>

Set in Layout, `scene_camera_projection_type="othographic"`

---

<div class="post-metadata">

### Author: ![bhalpin](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bhalpin](https://discourse.julialang.org/u/bhalpin)
#### Post date: [March 19, 2023, 1:36pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/6 "2023-03-19T13:36:50Z")

</div>

Thanks,

I can’t get that to work exactly in that form, but using it as a starting point I arrived at this snippet which works, and generates an orthographic projection (which from this angle reduces to a 2-D X-Y view):

```julia
using PlotlyJS

rw() = cumsum(randn(400))
trace1 = scatter3d(;x=rw(),y=rw(), z=rw(), mode="lines")
layout=Layout(scene=attr(camera=attr(eye=attr(x=0.0, y=0.0, z=10.0),
                                     projection=attr(type="orthographic"))))
plot([trace1], layout)

```

 ![pjstest](https://global.discourse-cdn.com/julialang/original/3X/a/7/a7a2b0fb48faaeec72e893d340d655193f4f68a0.png)

This is a solution for me, but the problem remains that the example in the docs at [3D projection · Plots](https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/) doesn’t work as advertised. Who should I tell?

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [March 19, 2023, 2:20pm UTC](https://discourse.julialang.org/t/plotlyjs-doesnt-implement-orthographic-projection-option/96203/7 "2023-03-19T14:20:03Z")

</div>

What I posted is a path in a nested Dict interpreted as a tree with the root, `scene`. But finally you realized how to write it to have effect.  
You may open an issue on the PlotlyJS.jl.repo or better, a PR to improve the docs related to projection type.
