# Using Makie for Allotaxonometry

**URL:** <https://discourse.julialang.org/t/using-makie-for-allotaxonometry/73453>\
**Category:** Visualization\
**Tags:** question, plotting, makie\
**Created:** [December 21, 2021, 8:07pm UTC](https://discourse.julialang.org/t/using-makie-for-allotaxonometry/73453 "2021-12-21T20:07:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 22, 2021, 12:15am UTC](https://discourse.julialang.org/t/using-makie-for-allotaxonometry/73453/2 "2021-12-22T00:15:22Z")

</div>

There was some discussion about a rotated inset axis recently, might be interesting for you:

> [@Rotating Plots in Makie](https://discourse.julialang.org/t/rotating-plots-in-makie/72017):
>
> I’m interested in understanding how one can rotate a whole axis/plot in Makie, in order to produce visualizations like the one below. This solution was posted by Simon Danisch on Slack: 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(),)) …

> <https://github.com/MakieOrg/Makie.jl/issues/1476>
>
> I was trying to rotate a plot (and axis) to produce a visualization like this on…e below:
> !\[image\](https://user-images.githubusercontent.com/6407557/143333206-cf0b4206-8a6f-4d2f-864c-08b232fcd80d.png)
> I've posted the question and the following answer was given:
> \`\`\`julia
> fig = Figure()
> b = Axis(fig\[1, 1\])
> scene = Scene(fig.scene)
> campixel!(scene)
> ax = Axis(scene, bbox = MakieLayout.BBox(-100, 100, -100, 100))
> 
> for s in (scene, ax.scene)
> Makie.rotate!(s, Vec3f(0,0,1), -pi/4)
> translate!(s, Vec3f(300, 300, 100))
> end
> fig
> \`\`\`
> Unfortunately, this does not work on CairoMakie. As pointed out by @ffreyer who posted this solution: "This works for me in GLMakie but CairoMakie still has two problems - text gets transformed differently and disappears, and the background pane of the rotated axis doesn’t draw over the normal axis. I think these are things that need to fixed in CairoMakie though."

If `text!` doesn’t work correctly with `rotate!` (which I don’t think it does) you should still be able to do things manually. If you rotate the whole scene (i.e. ax.scene or f.scene.children[1]) you can get the pixel position within that scene for a data position with `px_pos = project(ax.scene, position)`. You can use that to plot text at the correct position by plotting to `f.scene`, which is in pixel units. You need to add the offset from `ax.scene` though, so it becomes

```julia
positions = Point2f[(1, 1), (2, 1), (3, 1)]

fig, ax, p = scatter(positions, color = [:red, :green, :blue])
rotate!(ax.scene, Vec3f(0,0,1), pi/4)
xlims!(ax, -0.5, 2.0)
ylims!(ax, 1, 3)

px_positions = map(positions) do pos
    Makie.project(ax.scene, pos) + minimum(ax.scene.px_area[])
end
text!(
    fig.scene, ["First", "Second", "Third"], position = px_positions, 
    color = [:red, :green, :blue], rotation = [0.0, pi/4, -pi/4]
)

fig

```

or

```julia
px_positions = map(ax.scene.camera.projectionview, ax.scene.px_area) do _, px_area
    map(positions) do pos
        Makie.project(ax.scene, pos) + minimum(px_area)
    end
end

```

to make the text positions update automatically.

 ![Screenshot from 2021-12-22 01-13-22](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff25a0350fe8db9dcdae2f92eab8f39deac68794.png)

---

_[View the full topic](https://discourse.julialang.org/t/using-makie-for-allotaxonometry/73453)._
