# How could I enable rotation with mouse using PyPlot in Julia

**URL:** https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493
**Category:** New to Julia
**Created:** [June 27, 2017, 1:58pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493 "2017-06-27T13:58:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)
#### Post date: [June 27, 2017, 1:58pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/1 "2017-06-27T13:58:48Z")

</div>

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:

````nohighlight
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.
````

---

<div class="post-metadata">

### Author: ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)
#### Post date: [June 27, 2017, 2:04pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/2 "2017-06-27T14:04:33Z")

</div>

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

```julia
ion()

```

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

---

<div class="post-metadata">

### Author: ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)
#### Post date: [June 27, 2017, 2:15pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/3 "2017-06-27T14:15:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)
#### Post date: [June 27, 2017, 2:30pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/4 "2017-06-27T14:30:51Z")

</div>

Put whatever code you want to run when Julia starts in your [.juliarc.jl](https://docs.julialang.org/en/stable/manual/getting-started/#Getting-Started-1) 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.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 27, 2017, 6:32pm UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/5 "2017-06-27T18:32:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)
#### Post date: [June 28, 2017, 7:18am UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/6 "2017-06-28T07:18:05Z")

</div>

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:

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

---

<div class="post-metadata">

### Author: ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)
#### Post date: [June 28, 2017, 7:27am UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/7 "2017-06-28T07:27:49Z")

</div>

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

```julia
using PyPlot
ion()

```

---

<div class="post-metadata">

### Author: ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)
#### Post date: [June 28, 2017, 7:35am UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/8 "2017-06-28T07:35:22Z")

</div>

Thank you! It works now!

---

<div class="post-metadata">

### Author: ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)
#### Post date: [June 28, 2017, 7:36am UTC](https://discourse.julialang.org/t/how-could-i-enable-rotation-with-mouse-using-pyplot-in-julia/4493/9 "2017-06-28T07:36:14Z")

</div>

Thank you for your tip!
