How could I enable rotation with mouse using PyPlot in Julia


#1

I want to use something in Julia similar to rotate3d in Matlab so I can rotate the figures I produce. My base code looks like this:

function plotPatch()
    fig = figure()
    ax = Axes3D(fig) 
    ax[:mouse_init]()
    ax[:set_xlim3d](left=-0.6, right=0.6) 
    ax[:set_ylim3d](bottom=-0.6, top=0.6)
    ax[:set_zlim3d](bottom=-0.6, top=0.6)      
end```

I've googled this and I found: ```ax[:mouse_init]() ```  but nothing happens when I include that in the code.. (no error messages but I'm still not able to rotate the plot). Could I solve it in another way? I'd like to use PyPlot for this therefore I'm especially thankful for tips on how to solve this using PyPlot if that is possible.

#2

It works for me without adding any additional code or clicking any buttons. The only non-default PyPlot option I have is interactive plotting.

ion()

It works without the ax[:mouse_init]() line as well.


#3

Okay, how do you chose ion() as non-default PyPlot option in Julia?


#4

Put whatever code you want to run when Julia starts in your .juliarc.jl file. I like to put in packages and paths that I use every day in there as well. Look about halfway down that page I linked to to find reference to .juliarc.jl.


#5

Try with Plots.jl and the plotlyjs backend. The output looks fantastic and is very interactive.


#6

Thank you for your help. I’ve created the .juliarc.jl file but I still don’t understand how I should include ion()? Maybe my question is just how to use ion(). I googled it and found the python code:

plt.ion()
plt.plot([1.6, 2.7])``` 
but I still don't understand how to transform this to Julia code?

#7

Put this in your .juliarc.jl file along with whatever else you want.

using PyPlot
ion()

#8

Thank you! It works now!


#9

Thank you for your tip!