From e13070cd6d8347b1819f1a919937eb35c831f02c Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 19 Aug 2016 02:22:12 -0400 Subject: [PATCH] working on twinx --- src/Plots.jl | 1 + src/layouts.jl | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Plots.jl b/src/Plots.jl index 3f5a1d5e..3d754d63 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -39,6 +39,7 @@ export current, default, with, + twinx, @userplot, @shorthands, diff --git a/src/layouts.jl b/src/layouts.jl index 7ada1982..a55689c3 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -712,3 +712,22 @@ function link_axes!(layout::GridLayout, link::Symbol) link_axes!(l, link) end end + +# ------------------------------------------------------------------------- + +"Adds a new, empty subplot overlayed on top of `sp`, with a mirrored y-axis and linked x-axis." +function twinx(sp::Subplot) + sp[:right_margin] = max(sp[:right_margin], 30px) + idx = length(sp.plt.subplots) + 1 + plot!( + sp.plt, + ymirror = true, + xlink = [sp], + inset = (sp[:subplot_index], bbox(0,0,1,1)), + bg_inside = nothing, + subplot = idx + ) + sp.plt[idx] +end + +twinx(plt::Plot = current()) = twinx(plt[1])