working on subplot
This commit is contained in:
parent
4e57f02f5b
commit
36047e2928
@ -5,9 +5,14 @@ module Plots
|
|||||||
using Colors
|
using Colors
|
||||||
|
|
||||||
export
|
export
|
||||||
Plot,
|
|
||||||
plotter,
|
plotter,
|
||||||
plot,
|
plot,
|
||||||
|
subplot,
|
||||||
|
|
||||||
|
plotter!,
|
||||||
|
plot!,
|
||||||
|
subplot!,
|
||||||
|
|
||||||
currentPlot,
|
currentPlot,
|
||||||
plotDefault,
|
plotDefault,
|
||||||
scatter,
|
scatter,
|
||||||
@ -15,8 +20,6 @@ export
|
|||||||
histogram,
|
histogram,
|
||||||
heatmap,
|
heatmap,
|
||||||
|
|
||||||
plotter!,
|
|
||||||
plot!,
|
|
||||||
currentPlot!,
|
currentPlot!,
|
||||||
plotDefault!,
|
plotDefault!,
|
||||||
scatter!,
|
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
|
# 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)
|
function getPlotKeywordArgs(kw, i::Int, n::Int)
|
||||||
d = Dict(kw)
|
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)
|
# default to a white background, but only on the initial call (so we don't change the background automatically)
|
||||||
if haskey(d, :background_color)
|
if haskey(d, :background_color)
|
||||||
outd[:background_color] = getRGBColor(d[:background_color])
|
d[:background_color] = getRGBColor(d[:background_color])
|
||||||
elseif n == 0
|
elseif n == 0
|
||||||
d[:background_color] = colorant"white"
|
d[:background_color] = colorant"white"
|
||||||
end
|
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)
|
for k in keys(PLOT_DEFAULTS)
|
||||||
plural = makeplural(k)
|
plural = makeplural(k)
|
||||||
if haskey(d, plural)
|
if haskey(d, plural)
|
||||||
outd[k] = d[plural][i]
|
d[k] = d[plural][i]
|
||||||
elseif haskey(d, k)
|
elseif haskey(d, k)
|
||||||
outd[k] = d[k]
|
d[k] = d[k]
|
||||||
else
|
else
|
||||||
outd[k] = PLOT_DEFAULTS[k]
|
d[k] = PLOT_DEFAULTS[k]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# once the plot is created, we can get line/marker colors
|
# once the plot is created, we can get line/marker colors
|
||||||
if n > 0
|
if n > 0
|
||||||
# update color
|
# update color
|
||||||
outd[:color] = getRGBColor(outd[:color], n)
|
d[:color] = getRGBColor(d[:color], n)
|
||||||
|
|
||||||
# update markercolor
|
# update markercolor
|
||||||
mc = outd[:markercolor]
|
mc = d[:markercolor]
|
||||||
mc = (mc == :match ? outd[:color] : getRGBColor(mc, n))
|
mc = (mc == :match ? d[:color] : getRGBColor(mc, n))
|
||||||
outd[:markercolor] = mc
|
d[:markercolor] = mc
|
||||||
|
|
||||||
# set label
|
# set label
|
||||||
label = outd[:label]
|
label = d[:label]
|
||||||
outd[:label] = string(label == "AUTO" ? "y_$n" : label, outd[:axis] == :left ? "" : " (R)")
|
d[:label] = string(label == "AUTO" ? "y_$n" : label, d[:axis] == :left ? "" : " (R)")
|
||||||
end
|
end
|
||||||
|
|
||||||
outd
|
d
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -137,7 +137,12 @@ doc"Build a vector of dictionaries which hold the keyword arguments for a call t
|
|||||||
|
|
||||||
# no args... 1 series
|
# no args... 1 series
|
||||||
function createKWargsList(plt::PlottingObject; kw...)
|
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
|
end
|
||||||
|
|
||||||
# create one series where y is vectors of numbers
|
# 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
|
for plt in subplt.plts
|
||||||
Qwt.refresh(plt.o)
|
Qwt.refresh(plt.o)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
# create a layout directly
|
# 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
|
# 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
|
# figure out how many rows/columns we need
|
||||||
if numrows == -1
|
if numrows == -1
|
||||||
@ -27,21 +27,21 @@ function SubPlotLayout(numplts::Int, numrows::Int, numcols::Int)
|
|||||||
i += cnt
|
i += cnt
|
||||||
end
|
end
|
||||||
|
|
||||||
SubPlotLayout(numplts, rowcounts)
|
SubplotLayout(numplts, rowcounts)
|
||||||
end
|
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.string(subplt::Subplot) = "Subplot{$(subplt.plotter) p=$(subplt.p) n=$(subplt.n)}"
|
||||||
Base.print(io::IO, subplt::SubPlot) = print(io, string(subplt))
|
Base.print(io::IO, subplt::Subplot) = print(io, string(subplt))
|
||||||
Base.show(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)
|
o = buildSubplotObject(plts, pkg, layout)
|
||||||
|
|
||||||
# create the object and do the plotting
|
# 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...)
|
subplot!(subplt, args...; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# # this adds to a specific subplot... most plot commands will flow through here
|
# # 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...)
|
kwList = createKWargsList(subplt, args...; kw...)
|
||||||
for (i,d) in enumerate(kwList)
|
for (i,d) in enumerate(kwList)
|
||||||
subplt.n += 1
|
subplt.n += 1
|
||||||
|
|||||||
@ -12,17 +12,17 @@ type Plot <: PlottingObject
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
type SubPlotLayout
|
type SubplotLayout
|
||||||
numplts::Int
|
numplts::Int
|
||||||
rowcounts::AbstractVector{Int}
|
rowcounts::AbstractVector{Int}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
type SubPlot <: PlottingObject
|
type Subplot <: PlottingObject
|
||||||
o # the underlying object
|
o # the underlying object
|
||||||
plts::Vector{Plot} # the individual plots
|
plts::Vector{Plot} # the individual plots
|
||||||
plotter::PlottingPackage
|
plotter::PlottingPackage
|
||||||
p::Int # number of plots
|
p::Int # number of plots
|
||||||
n::Int # number of series
|
n::Int # number of series
|
||||||
layout::SubPlotLayout
|
layout::SubplotLayout
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user