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

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):

``````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:

``````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?

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

``````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
``````
1 Like

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?):

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

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.