subplots and colors

This commit is contained in:
Thomas Breloff 2015-10-21 12:27:13 -04:00
parent 456c4019c4
commit ee80ce5ae6
5 changed files with 1011 additions and 2 deletions

926
examples/meetup/nnet.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,7 @@ const _masterColorList = [
function darken(c, v=0.1)
rgba = RGBA(c)
rgba = convert(RGBA, c)
r = max(0, min(rgba.r - v, 1))
g = max(0, min(rgba.g - v, 1))
b = max(0, min(rgba.b - v, 1))
@ -124,6 +124,12 @@ const _testColors = [colorant"darkblue", colorant"blueviolet", colorant"darkcya
:mlab => [RGB(0, 0.4470, 0.7410),RGB(0.4940, 0.1840, 0.5560),RGB(0.9290, 0.6940, 0.1250),
RGB(0.4660, 0.6740, 0.1880),RGB(0.3010, 0.7450, 0.9330),RGB(0.6350, 0.0780, 0.1840),
RGB(0.8500, 0.3250, 0.0980)],
:sb_deep => map(c->parse(Colorant,c), ["#4C72B0", "#55A868", "#C44E52", "#8172B2", "#CCB974", "#64B5CD"]),
:sb_muted => map(c->parse(Colorant,c), ["#4878CF", "#6ACC65", "#D65F5F", "#B47CC7", "#C4AD66", "#77BEDB"]),
:sb_pastl => map(c->parse(Colorant,c), ["#92C6FF", "#97F0AA", "#FF9F9A", "#D0BBFF", "#FFFEA3", "#B0E0E6"]),
:sb_bright => map(c->parse(Colorant,c), ["#003FFF", "#03ED3A", "#E8000B", "#8A2BE2", "#FFC400", "#00D7FF"]),
:sb_dark => map(c->parse(Colorant,c), ["#001C7F", "#017517", "#8C0900", "#7600A1", "#B8860B", "#006374"]),
:sb_colorblind=> map(c->parse(Colorant,c), ["#0072B2", "#009E73", "#D55E00", "#CC79A7", "#F0E442", "#56B4E9"]),
)
# # TODO: maybe try to include:

View File

@ -145,6 +145,8 @@ Create a series of plots:
subplot(y; n = 3, nr = 1) # create an automatic grid, but fix the number of rows to 1 (so there are n columns)
subplot(y; n = 3, nc = 1) # create an automatic grid, but fix the number of columns to 1 (so there are n rows)
subplot(y; layout = [1, 2]) # explicit layout by row... plot #1 goes by itself in the first row, plots 2 and 3 split the 2nd row (note the n kw is unnecessary)
subplot(plts, n; nr = -1, nc = -1) # build a layout from existing plots
subplot(plts, layout) # build a layout from existing plots
```
"""
function subplot(args...; kw...)
@ -191,6 +193,71 @@ function subplot(args...; kw...)
subplt
end
# ------------------------------------------------------------------------------------------------
# NOTE: for the subplot calls building from existing plots, we need the first plot to be separate to ensure dispatch calls this instead of the more general subplot(args...; kw...)
# grid layout
# function subplot{P}(plt1::Plot{P}, plts::Plot{P}...; nr::Integer = -1, nc::Integer = -1, link = false, linkx = false, linky = false)
function subplot{P}(plt1::Plot{P}, plts::Plot{P}...; kw...)
d = Dict(kw)
layout = subplotlayout(length(plts)+1, get(d, :nr, -1), get(d, :nc, -1))
subplot(vcat(plt1, plts...), layout, d) #, link || linkx, link || linky)
end
# explicit layout
function subplot{P,I<:Integer}(pltsPerRow::AVec{I}, plt1::Plot{P}, plts::Plot{P}...; kw...) #link = false, linkx = false, linky = false)
layout = subplotlayout(pltsPerRow)
subplot(vcat(plt1, plts...), layout, Dict(kw)) #, link || linkx, link || linky)
end
# this will be called internally
function subplot{P<:PlottingPackage}(plts::AVec{Plot{P}}, layout::SubplotLayout, d::Dict) #, linkx::Bool, linky::Bool)
p = length(layout)
n = sum([plt.n for plt in plts])
subplt = Subplot(nothing, collect(plts), P(), p, n, layout, Dict(), false, false, false, (r,c) -> (nothing,nothing))
# update links
for s in (:linkx, :linky, :linkfunc)
if haskey(d, s)
setfield!(subplt, s, d[s])
delete!(d, s)
end
end
# init (after plot creation)
if !subplt.initialized
subplt.initialized = buildSubplotObject!(subplt, false)
end
# add title, axis labels, ticks, etc
for (i,plt) in enumerate(subplt.plts)
di = copy(d)
for (k,v) in di
if typeof(v) <: AVec
di[k] = v[mod1(i, length(v))]
elseif typeof(v) <: AMat
m = size(v,2)
di[k] = (size(v,1) == 1 ? v[1, mod1(i, m)] : v[:, mod1(i, m)])
end
end
dumpdict(di, "Updating sp $i")
updatePlotItems(plt, di)
end
# handle links
subplt.linkx && linkAxis(subplt, true)
subplt.linky && linkAxis(subplt, false)
# set this to be current
current(subplt)
subplt
end
# TODO: hcat/vcat subplots and plots together arbitrarily
# ------------------------------------------------------------------------------------------------
"""
Adds to a subplot.
"""
@ -219,6 +286,7 @@ function subplot!(subplt::Subplot, args...; kw...)
preprocessArgs!(d)
dumpdict(d, "After subplot! preprocessing")
# process links. TODO: extract to separate function
for s in (:linkx, :linky, :linkfunc)
if haskey(d, s)
setfield!(subplt, s, d[s])
@ -265,6 +333,8 @@ function subplot!(subplt::Subplot, args...; kw...)
plot!(plt; di...)
end
# -- TODO: extract this section into a separate function... duplicates the other subplot ---------
# create the underlying object (each backend will do this differently)
if !subplt.initialized
subplt.initialized = buildSubplotObject!(subplt, false)
@ -292,6 +362,7 @@ function subplot!(subplt::Subplot, args...; kw...)
# set this to be current
current(subplt)
# --- end extract ----
# show it automatically?
if haskey(d, :show) && d[:show]

View File

@ -33,7 +33,7 @@ end
type Subplot{T<:PlottingPackage, L<:SubplotLayout} <: PlottingObject{T}
o # the underlying object
plts::Vector{Plot} # the individual plots
plts::Vector{Plot{T}} # the individual plots
backend::T
p::Int # number of plots
n::Int # number of series

View File

@ -19,6 +19,12 @@ include("../docs/example_generation.jl")
using Plots, FactCheck
import Images, ImageMagick
# if !isdefined(ImageMagick, :init_deps)
# function ImageMagick.init_deps()
# ccall((:MagickWandGenesis,libwand), Void, ())
# end
# end
function makeImageWidget(fn)
img = Gtk.GtkImageLeaf(fn)
vbox = Gtk.GtkBoxLeaf(:v)