PlotlyJS doesn't implement orthographic projection option

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/

The orthographic example is actually using perspective.

The options work as intended with GR.

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

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.

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

vs

https://docs.juliaplots.org/stable/gallery/plotlyjs/generated/plotlyjs-ref060/

Using direct PlotlyJS, not via Plots, the two projections are distinct:
perspective
orthographic

2 Likes

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.

Set in Layout, scene_camera_projection_type="othographic"

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):

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)

This is a solution for me, but the problem remains that the example in the docs at 3D projection · Plots doesn’t work as advertised. Who should I tell?

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.