# Linking axes

**URL:** <https://discourse.julialang.org/t/linking-axes/8633>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [January 27, 2018, 4:59am UTC](https://discourse.julialang.org/t/linking-axes/8633 "2018-01-27T04:59:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [January 27, 2018, 4:59am UTC](https://discourse.julialang.org/t/linking-axes/8633/1 "2018-01-27T04:59:50Z")

</div>

Do any of the plotting packages for Julia support linking the axes of plots, as well as interactive zooming/panning? I’ve found mention (though not in docs, only in GitHub issues) of a `link` kwarg in Plots.jl, but it didn’t work for me on 4 different backends (PlotlyJS, PyPlot, GR, InspectDR), but to no avail.

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [January 27, 2018, 5:12am UTC](https://discourse.julialang.org/t/linking-axes/8633/2 "2018-01-27T05:12:38Z")

</div>

Well, I should have tried one more thing before posting. Using PyPlot directly works:

```julia
julia> using PyPlot

julia> ax1=subplot(2,1,1)
PyObject <matplotlib.axes._subplots.AxesSubplot object at 0x12c6d6fd0>

julia> plot(randn(100,1))
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x139bb3dd0>

julia> ax2=subplot(2,1,2, sharex=ax1)
PyObject <matplotlib.axes._subplots.AxesSubplot object at 0x139c0fcd0>

julia> plot(randn(100,1))
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x139c49c90>

```

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [January 29, 2018, 5:10am UTC](https://discourse.julialang.org/t/linking-axes/8633/3 "2018-01-29T05:10:48Z")

</div>

In case you were still interested: _ **InspectDR** _ allows you to “link” x-axes (does not support y-axis links) - but you must use the module directly (“linking” not supported from the Plots.jl module).

“linking” is done implicitly when you plot curves on different plot “strips” (`strip=1` is bottom-most, `strip=2` is next up, …).

For example, if you were to generate a bode plot of `X(f)`, you would want to plot the magnitude & phase on different “strips”:

```julia-auto
wfrm = add(plot, f, X, strip=1)
wfrm = add(plot, f, phase(X), strip=2)

```

The sample directory provides examples of common usage in circuit design:

_ **Bode Plot:** _ [InspectDR.jl/sample/demo7.jl at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo7.jl)

_ **Mixed-signal “simulation”:** _ [InspectDR.jl/sample/demo10.jl at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo10.jl)

_ **Digital buffer “simulation”:** _ [InspectDR.jl/sample/demo11.jl at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo11.jl)

### Comments

Sample outputs can be found here: [FileRepo/InspectDR/sampleplots/README.md at master · ma-laforge/FileRepo · GitHub](https://github.com/ma-laforge/FileRepo/blob/master/InspectDR/sampleplots/README.md)

I also personally find pan/zoom interactivity more responsive with InspectDR. The feel is also more consistent with other tools than what you get with PyPlot.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 29, 2018, 6:53am UTC](https://discourse.julialang.org/t/linking-axes/8633/4 "2018-01-29T06:53:29Z")

</div>

This should work in Plots. What code have you tried?

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [January 29, 2018, 4:56pm UTC](https://discourse.julialang.org/t/linking-axes/8633/5 "2018-01-29T16:56:39Z")

</div>

For example:

```julia
using Plots
plotlyjs()
plot(randn(100,2), layout=2, link=:x)

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 29, 2018, 9:04pm UTC](https://discourse.julialang.org/t/linking-axes/8633/6 "2018-01-29T21:04:18Z")

</div>

Yeah I saw from the issue you opened that you expected the axis to stay linked when zooming using the plotlyjs gui - that does not work.

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [January 29, 2018, 9:48pm UTC](https://discourse.julialang.org/t/linking-axes/8633/7 "2018-01-29T21:48:58Z")

</div>

Can you clarify what does work, as far as you know?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 29, 2018, 10:25pm UTC](https://discourse.julialang.org/t/linking-axes/8633/8 "2018-01-29T22:25:40Z")

</div>

Having the (x/y) axis limits aligned when you do the plot. The thing is that Plots does not receive any signals from the backend gui - so Plots does not know you’ve zoomed it.

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [January 29, 2018, 11:01pm UTC](https://discourse.julialang.org/t/linking-axes/8633/9 "2018-01-29T23:01:07Z")

</div>

Ah, there’s the confusion then. To me “link axis” means what the `linkaxes` command in MATLAB does: [Synchronize limits of multiple axes - MATLAB linkaxes](https://www.mathworks.com/help/matlab/ref/linkaxes.html)

I guess in matplotlib/PyPlot it goes by the kwarg name `sharex`.

Given that a backend such at PyPlot or PlotlyJS supports the linkaxes behavior that I’m after, does that mean that it’s possible to expose that via Plots?

Edit: Maybe best to keep discussion in one place: [https://github.com/JuliaPlots/Plots.jl/issues/1371](https://github.com/JuliaPlots/Plots.jl/issues/1371)
