Plots.jl: Need arg to control the viewing angle of 3D plots

Created on 30 May 2016  Â·  13Comments  Â·  Source: JuliaPlots/Plots.jl

Currently when using a 3D plotting routine we are given the default view angle with no way of changing it.

For the name, matplotlib uses view_init, matlab uses view, Mathematica uses ViewAngle. I like the last one the most (that is view_angle or viewangle) as it feels the least likely to be confused with something out of context.

good first issue

Most helpful comment

This was fixed in #1141

All 13 comments

I think camera is the most obvious representation, as view might mean a lot of things. It would be super helpful if someone could compile links to API docs for setting this with each backend.

+1 to camera

Matplotlib

http://matplotlib.org/mpl_toolkits/mplot3d/api.html
with the specific api information:

view_init(elev=None, azim=None)
Set the elevation and azimuth of the axes.

This can be used to rotate the axes programatically.

‘elev’ stores the elevation angle in the z plane. ‘azim’ stores the azimuth angle in the x,y plane.

if elev or azim are None (default), then the initial value is used which was specified in the Axes3D constructor.

Plotly/JS

https://plot.ly/javascript/reference/#layout-scene-camera
with some examples in python
https://plot.ly/python/3d-camera-controls/

It looks like you make the json information of the form

camera = {
"up": [x, y, z]
"center": [x, y, z]
"eye": [x, y, z]
}

where eye + center seems to control how the view angle works.

GR

can't figure out were to find the information :(

pgfplots?

Not sure if it is mapped in the julia package, but for raw pgfplots it is described
on pg.287 (section 4.11.1) under the "View Configuration". In brief:

/pgfplots/view={<azimuth>}{<elevation>} (initially {25}{30})
Changes both view angles of a 3D axis. The azimuth (first argument) is the horizontal angle which is rotated around the z axis. For a 3D plot, the z axis always points to the top. The elevation (second argument) is the vertical rotation around the (rotated) x axis. Positive elevation values indicate a view from above, negative a view from below. All values are measured in degree (but see trig format).

camera does jive with the plotly api, might be nice to have the type like they do as well with the center/eye/up.

Thanks @gabrielgellner!

I wonder if instead of the eye field it maybe should be lens or view since eye might be confusing with the good ol matrix function.

I also miss such option, it would be great to have it added.

camera = {
"up": [x, y, z]
"center": [x, y, z]
"eye": [x, y, z]
}

Would also work well with GLVisualize!

Is the option available already somehow?

For future reference, here's how I've dealt with this using the PyPlot-backend:

x = linspace(0,1)
plt = surface(x,x,(x,y)->x+y)
fig = plt.subplots[1].o
fig[:view_init](elev=50,azim=100)
PyPlot.draw()

It seems like calling savefig(plt, "img.png") resets the camera though...

I managed to create a gif using the following hack

strings = String[]
for (i,a) = enumerate(1:4:360)
    fig = plt.subplots[1].o
    fig[:view_init](azim=a)
    s = i >= 10 ? "image$(i).png" : "image0$(i).png"
    push!(strings,s)
    PyPlot.savefig("/tmp/"*strings[end])
    println(round(a/360,3), "% done")
end
anim = Plots.Animation("/tmp/", strings)
gif(anim, "/tmp/anim_fps20.gif", fps = 20)

A few caveats

  • The animation creator takes all png images in the folder and creates a gif using them. It is thus safer to create a temp folder and put the images there.
  • The animation creator puts img1.png and img10.png in the wrong order, it does not respect or even look at the list of strings in the Animation object, hence the extra 0 for images with numbers < 10.

The temporary solution provided by @anriseth doesn't seem to be working (anymore?) for me; I get:

MethodError: no method matching getindex(::Void, ::Symbol)

because plt.subplots[1].o is nothing before the plot is actually displayed, and after the plot has been displayed, changes made to the underlying PyObject don't seem to have any effect anymore.

This was fixed in #1141

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jebej picture jebej  Â·  4Comments

PallHaraldsson picture PallHaraldsson  Â·  4Comments

ereday picture ereday  Â·  3Comments

kleinschmidt picture kleinschmidt  Â·  3Comments

crstnbr picture crstnbr  Â·  3Comments