Linking axes

question
plotting

#1

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.


#2

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

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>


#3

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

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: https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo7.jl

Mixed-signal “simulation”: https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo10.jl

Digital buffer “simulation”: https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo11.jl

Comments

Sample outputs can be found here: 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.


#4

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


#5

For example:

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

#6

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.


#7

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


#8

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.


#9

Ah, there’s the confusion then. To me “link axis” means what the linkaxes command in MATLAB does: 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