# Makie: how to make a vertical (rotated by 90deg) lines! plot

**URL:** <https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [February 7, 2023, 1:28pm UTC](https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207 "2023-02-07T13:28:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaltsoplyn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaltsoplyn/32/46634_2.png) [@kaltsoplyn](https://discourse.julialang.org/u/kaltsoplyn)\
**Post date:** [February 7, 2023, 1:28pm UTC](https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207/1 "2023-02-07T13:28:16Z")

</div>

I can’t figure out a reasonably simple answer to this, and I’d guess the _must_ be one.

I want to create a `lines` plot rotated 90 degrees. Like, everything rotated: axis, labels, curves, the whole thing. Here’s a minimum working example (I could make it simpler, but this also outlines a potential real-world scenario):

```julia
with_theme(theme_light()) do 
    fig = Figure()
    ax_main = Axis(fig[1,1:2])
    ax_side = Axis(fig[1,3], xlabel = "x label", ylabel = "y label")
    Xs = Ys = -10:0.1:10
    contour!(ax_main, Xs, Ys, exp.((-Xs'.^2 .- Ys.^2)/25))

    lines!(ax_side, Xs, exp.(-Xs.^2/25)) # <- This I want rotated on its side
    
    fig
end

```

This produces the figure on the left in the picture attached below. What I want is - more or less - the figure on the right. Right now, in order to produce that rightmost figure, I’m manually flipping everything:

```julia
with_theme(theme_light()) do 
    Xs = Ys = -10:0.1:10
    fig = Figure()
    ax_main = Axis(fig[1,1:2])
    ax_side = Axis(fig[1,3], ylabel = "x label", xlabel = "y label", flip_ylabel = true, yticks = (-10:5:10, string.(10:-5:-10)))
    contour!(ax_main, Xs, Ys, exp.((-Xs'.^2 .- Ys.^2)/25))

    lines!(ax_side, exp.(-Xs.^2/25), reverse(Xs))
    
    fig
end

```

which I find extremely suboptimal: I have to switch everything x-related with everything y-related, I have to reverse the former-X-now-Y data, I have to _manually create_ reversed y-axis ticks, because reversing the data is not enough (?), I have to flip the y-label, and more… It’s becoming even more cumbersome given that such plots are produced in many places in my code, and sometimes I want them displayed horizontally, others vertically, so I’d really like to have a common codebase for producing both varieties.

So, question is, is there some simple solution that I’m missing here? Like some `orientation` or `direction`-like attribute or similar?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/d/3db0d56adf27da5c4769a6b5b78cb5b10f4eeb4d.png)

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [February 7, 2023, 2:14pm UTC](https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207/2 "2023-02-07T14:14:39Z")

</div>

nope, not `orientation` argument for lines, but, this might be of interest to you. It does what you want.

```plaintext
using GLMakie

with_theme(theme_light()) do 
    fig = Figure()
    ax_main = Axis(fig[1,1:2])
    ax_side = Axis(fig[1,3], xlabel = "y label", ylabel = "x label") # well, just flip these ones
    Xs = Ys = -10:0.1:10
    contour!(ax_main, Xs, Ys, exp.((-Xs'.^2 .- Ys.^2)/25))

    obj = lines!(ax_side, Xs, exp.(-Xs.^2/25))
    rotate!(obj, -π/2) # rotates your plotted object
    ax_side.yreversed = true
    fig
end

```

---

<div class="post-metadata">

**Author:** ![kaltsoplyn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaltsoplyn/32/46634_2.png) [@kaltsoplyn](https://discourse.julialang.org/u/kaltsoplyn)\
**Post date:** [February 7, 2023, 3:13pm UTC](https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207/3 "2023-02-07T15:13:50Z")

</div>

Hi, and thanks for the reply.  
Yes and no, this kinda does what I want, but not entirely. I, too, did figure out eventually how to dig into the axis, retrieve the scene and rotate it, but I find it to be a half measure, because the axis is not rescaled, and any custom ticks etc. remain on the axes they were defined on. For example, to rescale the axis in your solution (i.e., flip the `x` and `y` limits), I have to add something like (is there some auto rescale function in Makie?):

```julia
...
    origins, widths = (ax_side.finallimits[].origin, ax_side.finallimits[].widths)
    ylims!(ax_side, origins[1] .+ (0, widths[1]))
    xlims!(ax_side, origins[2] .+ (0, widths[2]))
...

```

And if I had used custom ticks, say on the x-axis (which is quite common e.g., for trigonometric functions), these wouldn’t transfer upon rotation.

However, I’ll take it that there’s no real axis rotation for the time being, maybe ever, and I’ll probably write some convenience function of my own based on the above. Thanks!

---

<div class="post-metadata">

**Author:** ![kaltsoplyn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaltsoplyn/32/46634_2.png) [@kaltsoplyn](https://discourse.julialang.org/u/kaltsoplyn)\
**Post date:** [February 8, 2023, 5:45pm UTC](https://discourse.julialang.org/t/makie-how-to-make-a-vertical-rotated-by-90deg-lines-plot/94207/4 "2023-02-08T17:45:46Z")

</div>

Actually it’s a rabbit hole 😃

Rotating may or may not work for plots that possess enough symmetry, but mixing in just slightly more complexity blows things out of the water. I guess this is why there’s no easy `rotate!(ax::Axis, ...)` function available.
