From 36047e2928ace7ebec94055b00f4acdeb293b4ec Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 11 Sep 2015 15:04:33 -0400 Subject: [PATCH] working on subplot --- src/Plots.jl | 9 ++++++--- src/args.jl | 31 ++++++++++++++++++------------- src/plot.jl | 7 ++++++- src/qwt.jl | 10 ++++++++-- src/subplot.jl | 20 ++++++++++---------- src/types.jl | 6 +++--- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index a112bb2e..b120d89c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -5,9 +5,14 @@ module Plots using Colors export - Plot, plotter, plot, + subplot, + + plotter!, + plot!, + subplot!, + currentPlot, plotDefault, scatter, @@ -15,8 +20,6 @@ export histogram, heatmap, - plotter!, - plot!, currentPlot!, plotDefault!, scatter!, diff --git a/src/args.jl b/src/args.jl index 41f1a39d..2a300403 100644 --- a/src/args.jl +++ b/src/args.jl @@ -85,42 +85,47 @@ end # note: i is the index of this series within this call, n is the index of the series from all calls to plot/subplot function getPlotKeywordArgs(kw, i::Int, n::Int) d = Dict(kw) - outd = Dict() + + if n == 0 + delete!(d, :x) + delete!(d, :y) + end + # outd = Dict() # default to a white background, but only on the initial call (so we don't change the background automatically) if haskey(d, :background_color) - outd[:background_color] = getRGBColor(d[:background_color]) + d[:background_color] = getRGBColor(d[:background_color]) elseif n == 0 d[:background_color] = colorant"white" end - # fill in outd with either 1) plural value, 2) value, 3) default + # fill in d with either 1) plural value, 2) value, 3) default for k in keys(PLOT_DEFAULTS) plural = makeplural(k) if haskey(d, plural) - outd[k] = d[plural][i] + d[k] = d[plural][i] elseif haskey(d, k) - outd[k] = d[k] + d[k] = d[k] else - outd[k] = PLOT_DEFAULTS[k] + d[k] = PLOT_DEFAULTS[k] end end # once the plot is created, we can get line/marker colors if n > 0 # update color - outd[:color] = getRGBColor(outd[:color], n) + d[:color] = getRGBColor(d[:color], n) # update markercolor - mc = outd[:markercolor] - mc = (mc == :match ? outd[:color] : getRGBColor(mc, n)) - outd[:markercolor] = mc + mc = d[:markercolor] + mc = (mc == :match ? d[:color] : getRGBColor(mc, n)) + d[:markercolor] = mc # set label - label = outd[:label] - outd[:label] = string(label == "AUTO" ? "y_$n" : label, outd[:axis] == :left ? "" : " (R)") + label = d[:label] + d[:label] = string(label == "AUTO" ? "y_$n" : label, d[:axis] == :left ? "" : " (R)") end - outd + d end diff --git a/src/plot.jl b/src/plot.jl index 3e4bb97b..e6ab6bff 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -137,7 +137,12 @@ doc"Build a vector of dictionaries which hold the keyword arguments for a call t # no args... 1 series function createKWargsList(plt::PlottingObject; kw...) - [getPlotKeywordArgs(kw, 1, plt.n + 1)] + d = Dict(kw) + @assert haskey(d, :y) + if !haskey(d, :x) + d[:x] = 1:length(d[:y]) + end + [getPlotKeywordArgs(d, 1, plt.n + 1)] end # create one series where y is vectors of numbers diff --git a/src/qwt.jl b/src/qwt.jl index c64a1d6d..0b4e0c95 100644 --- a/src/qwt.jl +++ b/src/qwt.jl @@ -44,9 +44,15 @@ savepng(::QwtPackage, plt::PlottingObject, fn::String, args...) = Qwt.savepng(pl # ------------------------------- -# subplot(::QwtPackage, args...; kw...) = Qwt.subplot(args...; kw...) +# # create the underlying object (each backend will do this differently) +# o = buildSubplotObject(plts, pkg, layout) -function Base.display(::QwtPackage, subplt::SubPlot) +function buildSubplotObject(plts::Vector{Plot}, pkg::QwtPackage, layout::SubplotLayout) + Qwt.vsplitter([Qwt.hsplitter([plt.o for plt in plts[i:(i+rowcnt-1)]]...) for rowcnt in layout.rowcounts]...) +end + + +function Base.display(::QwtPackage, subplt::Subplot) for plt in subplt.plts Qwt.refresh(plt.o) end diff --git a/src/subplot.jl b/src/subplot.jl index e34f5b86..9caeb3c1 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -1,10 +1,10 @@ # create a layout directly -SubPlotLayout(rowcounts::AbstractVector{Int}) = SubPlotLayout(sum(rowcounts), rowcounts) +SubplotLayout(rowcounts::AbstractVector{Int}) = SubplotLayout(sum(rowcounts), rowcounts) # create a layout given counts... numrows/numcols == -1 implies we figure out a good number automatically -function SubPlotLayout(numplts::Int, numrows::Int, numcols::Int) +function SubplotLayout(numplts::Int, numrows::Int, numcols::Int) # figure out how many rows/columns we need if numrows == -1 @@ -27,21 +27,21 @@ function SubPlotLayout(numplts::Int, numrows::Int, numcols::Int) i += cnt end - SubPlotLayout(numplts, rowcounts) + SubplotLayout(numplts, rowcounts) end -Base.length(layout::SubPlotLayout) = layout.numplts +Base.length(layout::SubplotLayout) = layout.numplts # ------------------------------------------------------------ -Base.string(subplt::SubPlot) = "SubPlot{$(subplt.plotter) p=$(subplt.p) n=$(subplt.n)}" -Base.print(io::IO, subplt::SubPlot) = print(io, string(subplt)) -Base.show(io::IO, subplt::SubPlot) = print(io, string(subplt)) +Base.string(subplt::Subplot) = "Subplot{$(subplt.plotter) p=$(subplt.p) n=$(subplt.n)}" +Base.print(io::IO, subplt::Subplot) = print(io, string(subplt)) +Base.show(io::IO, subplt::Subplot) = print(io, string(subplt)) -getplot(subplt::SubPlot) = subplt.plts[mod1(subplt.n, subplt.p)] +getplot(subplt::Subplot) = subplt.plts[mod1(subplt.n, subplt.p)] # ------------------------------------------------------------ @@ -76,7 +76,7 @@ function subplot(args...; kw...) o = buildSubplotObject(plts, pkg, layout) # create the object and do the plotting - subplt = SubPlot(o, plts, pkg, length(layout), 0, layout) + subplt = Subplot(o, plts, pkg, length(layout), 0, layout) subplot!(subplt, args...; kw...) end @@ -97,7 +97,7 @@ end # # this adds to a specific subplot... most plot commands will flow through here -function subplot!(subplt::SubPlot, args...; kw...) +function subplot!(subplt::Subplot, args...; kw...) kwList = createKWargsList(subplt, args...; kw...) for (i,d) in enumerate(kwList) subplt.n += 1 diff --git a/src/types.jl b/src/types.jl index 6bf4fab9..248f485d 100644 --- a/src/types.jl +++ b/src/types.jl @@ -12,17 +12,17 @@ type Plot <: PlottingObject end -type SubPlotLayout +type SubplotLayout numplts::Int rowcounts::AbstractVector{Int} end -type SubPlot <: PlottingObject +type Subplot <: PlottingObject o # the underlying object plts::Vector{Plot} # the individual plots plotter::PlottingPackage p::Int # number of plots n::Int # number of series - layout::SubPlotLayout + layout::SubplotLayout end \ No newline at end of file