# Is there a simple way to swap the x and y axes in \`Plots.jl\` after a figure is plotted?

**URL:** <https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [September 7, 2023, 5:32am UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599 "2023-09-07T05:32:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [September 7, 2023, 5:32am UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599/1 "2023-09-07T05:32:10Z")

</div>

Note this is not `flip`, which flips the x and y axes by themselves. I want to exchange the y and x axes, like a transposition of the figure.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 7, 2023, 12:13pm UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599/2 "2023-09-07T12:13:52Z")

</div>

To transpose the plot **after** the figure has been plotted, you could do:

```julia
using Plots

x = range(0,2π,100)
y = sin.(x)
plot(x,y)

p = Plots.current()
y1 = p.series_list[1][:x]
x1 = p.series_list[1][:y]
plot(x1, y1)

```

---

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [September 7, 2023, 10:24pm UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599/3 "2023-09-07T22:24:52Z")

</div>

Thank you. Also, according to @SimonChrist on Slack, `permute=(:x, :y)` also works.

```julia
using Plots

x = range(0, 2π, 100)
y = sin.(x)
plot(x, y; permute=(:x, :y))

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 8, 2023, 7:42am UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599/4 "2023-09-08T07:42:24Z")

</div>

> [@singularitti](#):
>
> `plot(x, y; permute=(:x, :y))`

That doesn’t seem to work **after** a figure is plotted (as per OP’s title).  
Also, in that case it is simpler to write: `plot(y, x)` for the same result.

---

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [September 8, 2023, 7:43am UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599/5 "2023-09-08T07:43:11Z")

</div>

You are right. Thanks!

Actually, what I want is something that I can put into my custom recipes. So

```julia
@recipe function f(args...)
    ...
    permute-->(:x, :y)
    ...
end

```

is what I finally want. There is some confusion in the question. Sorry!
