# Rotating plot around line in Makie

**URL:** <https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [December 13, 2021, 5:32pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036 "2021-12-13T17:32:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [December 13, 2021, 5:32pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/1 "2021-12-13T17:32:44Z")

</div>

Hey amazing Makie people!

I would like to rotate a heatmap around a given line in a 3d scene.  
So far `rotate!(plt, qrotation(Vec3([0, 1, 0]), pi))` works great but I can only rotate against the `x,y,z` axis. How can I rotate with respect to a translated axis?

I already found this [question](https://discourse.julialang.org/t/rotating-plots-in-makie/72017) about rotating plots but there was no solution for my problem

Thanks!

---

<div class="post-metadata">

**Author:** ![davibarreira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davibarreira/32/20270_2.png) [@davibarreira](https://discourse.julialang.org/u/davibarreira)\
**Post date:** [December 13, 2021, 5:44pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/2 "2021-12-13T17:44:27Z")

</div>

@theogf , the working solution for CairoMakie was to turn it into a png and then place it within another plot 😢

---

<div class="post-metadata">

**Author:** ![davibarreira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davibarreira/32/20270_2.png) [@davibarreira](https://discourse.julialang.org/u/davibarreira)\
**Post date:** [December 13, 2021, 5:46pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/3 "2021-12-13T17:46:36Z")

</div>

Here is the code:

```julia
using GLMakie

f, ax, pl = barplot(rand(5), bar_labels=:y, figure=(resolution=(500, 500),))
hideydecorations!(ax)
hidespines!(ax, :t, :r, :l)
hidexdecorations!(ax, ticks=false)
tightlimits!(ax)
f
img = Makie.colorbuffer(ax.scene)

f, ax, pl = scatter(rand(Point2f, 100), axis=(aspect = DataAspect(),))
impl = image!(ax, 0..1, 0..1, rotr90(img))
display(f)

rotate!(impl, -0.25pi)
translate!(impl, 0.5, 1.2, 0)
xlims!(ax, 0, 2)
ylims!(ax, 0, 2)

```

Code from [Simon Danisch](https://app.slack.com/team/U66SGEWAC)

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [December 13, 2021, 5:50pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/4 "2021-12-13T17:50:12Z")

</div>

That will not work for me as I need to make an animation 😢  
Here is something I attempted

```julia
half_axis = Vec3([0, -1, 0])
val = 10
for i in 1:nsteps
            m_ϵ = qrotation(half_axis, i * π / nsteps)
            translate!(plt2, Vec3([-val, 0, 0]))
            rotate!(Accum, plt2, m_ϵ)
            translate!(Accum, plt2, Vec3([val, 0, 0]))
            sleep(0.01)
end

```

But this just makes the plot jumps around everywhere 😆

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [December 13, 2021, 5:50pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/5 "2021-12-13T17:50:56Z")

</div>

I don’t think the transformation system lets pick an origin for a rotation. But you can build your own model matrix to translate the heatmap, then rotate it, then translate it back:

```julia
model = 
    Makie.translationmatrix(axis_origin) *
    Makie.rotationmatrix(qrotation(axis, angle)) *
    Makie.translationmatrix(-axis_origin)
plt.model[] = model

```

(If that doesn’t work you may need to pass the model matrix when you create the plot. I vaguely remember some issue there.)

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [December 13, 2021, 5:55pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/6 "2021-12-13T17:55:36Z")

</div>

Alternatively you can define your heatmap so that it rotates the way you want (i.e. heatmap(-1…1, -1…1, data) if you want to rotate around the center) and then rotate and translate with the normal system. The order of operations there is always rotation first, scale and translation after.

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [December 13, 2021, 7:23pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/7 "2021-12-13T19:23:50Z")

</div>

I ended up centering the heatmap as you proposed @ffreyer, but this stops me from adding more nice stuff unfortunately 🙂

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [December 13, 2021, 7:24pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036/8 "2021-12-13T19:24:48Z")

</div>

I also saw one can pass a transformation so by doing `A (x - v) + v` I guess this could be somehow done
