working on subplot
This commit is contained in:
parent
4e57f02f5b
commit
36047e2928
@ -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!,
|
||||
|
||||
31
src/args.jl
31
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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
10
src/qwt.jl
10
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user