titles and sub-layouts
This commit is contained in:
parent
327f235af9
commit
bfc3fc1dec
12
src/args.jl
12
src/args.jl
@ -161,8 +161,7 @@ _series_defaults[:subplot] = :auto # which subplot(s) does this se
|
|||||||
|
|
||||||
const _plot_defaults = KW()
|
const _plot_defaults = KW()
|
||||||
|
|
||||||
_plot_defaults[:title] = ""
|
_plot_defaults[:plot_title] = ""
|
||||||
_plot_defaults[:titlefont] = font(14)
|
|
||||||
_plot_defaults[:background_color] = colorant"white" # default for all backgrounds
|
_plot_defaults[:background_color] = colorant"white" # default for all backgrounds
|
||||||
_plot_defaults[:background_color_outside] = :match # background outside grid
|
_plot_defaults[:background_color_outside] = :match # background outside grid
|
||||||
_plot_defaults[:foreground_color] = :auto # default for all foregrounds, and title color
|
_plot_defaults[:foreground_color] = :auto # default for all foregrounds, and title color
|
||||||
@ -184,6 +183,8 @@ _plot_defaults[:overwrite_figure] = true
|
|||||||
const _subplot_defaults = KW()
|
const _subplot_defaults = KW()
|
||||||
|
|
||||||
_subplot_defaults[:title] = ""
|
_subplot_defaults[:title] = ""
|
||||||
|
_subplot_defaults[:title_location] = :center # also :left or :right
|
||||||
|
_subplot_defaults[:titlefont] = font(14)
|
||||||
_subplot_defaults[:background_color_subplot] = :match # default for other bg colors... match takes plot default
|
_subplot_defaults[:background_color_subplot] = :match # default for other bg colors... match takes plot default
|
||||||
_subplot_defaults[:background_color_legend] = :match # background of legend
|
_subplot_defaults[:background_color_legend] = :match # background of legend
|
||||||
_subplot_defaults[:background_color_inside] = :match # background inside grid
|
_subplot_defaults[:background_color_inside] = :match # background inside grid
|
||||||
@ -378,6 +379,7 @@ add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio)
|
|||||||
add_aliases(:match_dimensions, :transpose, :transpose_z)
|
add_aliases(:match_dimensions, :transpose, :transpose_z)
|
||||||
add_aliases(:subplot, :sp, :subplt, :splt)
|
add_aliases(:subplot, :sp, :subplt, :splt)
|
||||||
add_aliases(:projection, :proj)
|
add_aliases(:projection, :proj)
|
||||||
|
add_aliases(:title_location, :title_loc, :titleloc)
|
||||||
|
|
||||||
|
|
||||||
# add all pluralized forms to the _keyAliases dict
|
# add all pluralized forms to the _keyAliases dict
|
||||||
@ -625,6 +627,12 @@ function preprocessArgs!(d::KW)
|
|||||||
# # end
|
# # end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
# # if title is just a single string, then assume we want plot_title
|
||||||
|
# # TODO: make a decision if this is correct
|
||||||
|
# if haskey(d, :title) && typeof(d[:title]) <: AbstractString
|
||||||
|
# d[:plot_title] = pop!(d, :title)
|
||||||
|
# end
|
||||||
|
|
||||||
# handle line args
|
# handle line args
|
||||||
for arg in wraptuple(pop!(d, :line, ()))
|
for arg in wraptuple(pop!(d, :line, ()))
|
||||||
processLineArg(d, arg)
|
processLineArg(d, arg)
|
||||||
|
|||||||
@ -293,13 +293,17 @@ end
|
|||||||
function py_bbox_axis(ax, letter)
|
function py_bbox_axis(ax, letter)
|
||||||
ticks = py_bbox_ticks(ax, letter)
|
ticks = py_bbox_ticks(ax, letter)
|
||||||
labels = py_bbox_axislabel(ax, letter)
|
labels = py_bbox_axislabel(ax, letter)
|
||||||
# @show ticks labels ticks+labels
|
letter == "x" && @show ticks labels ticks+labels
|
||||||
ticks + labels
|
ticks + labels
|
||||||
end
|
end
|
||||||
|
|
||||||
# get a bounding box for the title area
|
# get a bounding box for the title area
|
||||||
function py_bbox_title(ax)
|
function py_bbox_title(ax)
|
||||||
py_bbox(ax[:title])
|
bb = defaultbox
|
||||||
|
for s in (:title, :_left_title, :_right_title)
|
||||||
|
bb = bb + py_bbox(ax[s])
|
||||||
|
end
|
||||||
|
bb
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: need to compute each of these by subtracting the plotarea position from
|
# TODO: need to compute each of these by subtracting the plotarea position from
|
||||||
@ -318,6 +322,7 @@ function compute_min_padding(sp::Subplot{PyPlotBackend}, func::Function, mult::N
|
|||||||
ax = sp.o
|
ax = sp.o
|
||||||
plotbb = py_bbox(ax)
|
plotbb = py_bbox(ax)
|
||||||
# @show func, mult plotbb
|
# @show func, mult plotbb
|
||||||
|
# @show func, py_bbox_axis(ax, "x")
|
||||||
padding = 0mm
|
padding = 0mm
|
||||||
for bb in (py_bbox_axis(ax, "x"),
|
for bb in (py_bbox_axis(ax, "x"),
|
||||||
py_bbox_axis(ax, "y"),
|
py_bbox_axis(ax, "y"),
|
||||||
@ -329,6 +334,13 @@ function compute_min_padding(sp::Subplot{PyPlotBackend}, func::Function, mult::N
|
|||||||
end
|
end
|
||||||
# @show padding
|
# @show padding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# if func == top
|
||||||
|
# titlebbox = py_bbox_title(ax)
|
||||||
|
# padding = max(padding, height(titlebbox))
|
||||||
|
# @show titlebbox height(titlebbox),padding
|
||||||
|
# end
|
||||||
|
|
||||||
padding
|
padding
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -582,7 +594,7 @@ function _add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# ax = getAxis(plt, d[:axis])
|
# ax = getAxis(plt, d[:axis])
|
||||||
ax = getAxis(plt, series)
|
ax = getAxis(plt, series)
|
||||||
x, y, z = d[:x], d[:y], d[:z]
|
x, y, z = d[:x], d[:y], d[:z]
|
||||||
@show typeof((x,y,z))
|
# @show typeof((x,y,z))
|
||||||
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||||
|
|
||||||
# handle zcolor and get c/cmap
|
# handle zcolor and get c/cmap
|
||||||
@ -1058,18 +1070,30 @@ end
|
|||||||
|
|
||||||
function addPyPlotTicks(ax, ticks, letter)
|
function addPyPlotTicks(ax, ticks, letter)
|
||||||
ticks == :auto && return
|
ticks == :auto && return
|
||||||
|
axis = ax[symbol(letter,"axis")]
|
||||||
|
# tickfunc = symbol("set_", letter, "ticks")
|
||||||
|
# labfunc = symbol("set_", letter, "ticklabels")
|
||||||
if ticks == :none || ticks == nothing
|
if ticks == :none || ticks == nothing
|
||||||
ticks = zeros(0)
|
# ax[][:set_major_locator]
|
||||||
|
# ax[tickfunc]([])
|
||||||
|
# ax[labfunc]([])
|
||||||
|
kw = KW()
|
||||||
|
for dir in (:top,:bottom,:left,:right)
|
||||||
|
kw[dir] = kw[symbol(:label,dir)] = "off"
|
||||||
|
end
|
||||||
|
axis[:set_tick_params](;which="both", kw...)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ttype = ticksType(ticks)
|
ttype = ticksType(ticks)
|
||||||
tickfunc = symbol("set_", letter, "ticks")
|
|
||||||
labfunc = symbol("set_", letter, "ticklabels")
|
|
||||||
if ttype == :ticks
|
if ttype == :ticks
|
||||||
ax[tickfunc](ticks)
|
# ax[tickfunc](ticks)
|
||||||
|
axis[:set_ticks](ticks)
|
||||||
elseif ttype == :ticks_and_labels
|
elseif ttype == :ticks_and_labels
|
||||||
ax[tickfunc](ticks[1])
|
# ax[tickfunc](ticks[1])
|
||||||
ax[labfunc](ticks[2])
|
# ax[labfunc](ticks[2])
|
||||||
|
axis[:set_ticks](ticks[1])
|
||||||
|
axis[:set_ticklabels](ticks[2])
|
||||||
else
|
else
|
||||||
error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
|
error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
|
||||||
end
|
end
|
||||||
@ -1119,17 +1143,30 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
# guidesz = get(d, :guidefont, spargs[:guidefont]).pointsize
|
# guidesz = get(d, :guidefont, spargs[:guidefont]).pointsize
|
||||||
|
|
||||||
# title
|
# title
|
||||||
haskey(d, :title) && ax[:set_title](d[:title])
|
if haskey(spargs, :title)
|
||||||
ax[:title][:set_fontsize](plt.plotargs[:titlefont].pointsize)
|
loc = lowercase(string(spargs[:title_location]))
|
||||||
|
field = if loc == "left"
|
||||||
|
:_left_title
|
||||||
|
elseif loc == "right"
|
||||||
|
:_right_title
|
||||||
|
else
|
||||||
|
:title
|
||||||
|
end
|
||||||
|
ax[field][:set_text](spargs[:title])
|
||||||
|
ax[field][:set_fontsize](spargs[:titlefont].pointsize)
|
||||||
|
ax[field][:set_color](getPyPlotColor(spargs[:titlefont].color))
|
||||||
|
ax[:set_title](spargs[:title], loc = loc)
|
||||||
|
# TODO: set other font attributes
|
||||||
|
end
|
||||||
|
|
||||||
# axes = [ax]
|
# axes = [ax]
|
||||||
# # handle right y axis
|
# # handle right y axis
|
||||||
# axes = [getLeftAxis(figorax)]
|
# axes = [getLeftAxis(figorax)]
|
||||||
# if usingRightAxis(plt)
|
# if usingRightAxis(plt)
|
||||||
# push!(axes, getRightAxis(figorax))
|
# push!(axes, getRightAxis(figorax))
|
||||||
# if get(d, :yrightlabel, "") != ""
|
# if get(spargs, :yrightlabel, "") != ""
|
||||||
# rightax = getRightAxis(figorax)
|
# rightax = getRightAxis(figorax)
|
||||||
# rightax[:set_ylabel](d[:yrightlabel])
|
# rightax[:set_ylabel](spargs[:yrightlabel])
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
@ -1137,7 +1174,7 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
axissym = symbol(letter, :axis)
|
axissym = symbol(letter, :axis)
|
||||||
axis = spargs[axissym]
|
axis = spargs[axissym]
|
||||||
# @show axis
|
# @show axis
|
||||||
# DD(axis.d, "updateplot")
|
# DD(axis.spargs, "updateplot")
|
||||||
# @show haskey(ax, axissym)
|
# @show haskey(ax, axissym)
|
||||||
haskey(ax, axissym) || continue
|
haskey(ax, axissym) || continue
|
||||||
applyPyPlotScale(ax, axis[:scale], letter)
|
applyPyPlotScale(ax, axis[:scale], letter)
|
||||||
@ -1154,7 +1191,7 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
lab[:set_fontsize](axis[:tickfont].pointsize)
|
lab[:set_fontsize](axis[:tickfont].pointsize)
|
||||||
lab[:set_rotation](axis[:rotation])
|
lab[:set_rotation](axis[:rotation])
|
||||||
end
|
end
|
||||||
if get(d, :grid, false)
|
if get(spargs, :grid, false)
|
||||||
fgcolor = getPyPlotColor(spargs[:foreground_color_grid])
|
fgcolor = getPyPlotColor(spargs[:foreground_color_grid])
|
||||||
tmpax[axissym][:grid](true, color = fgcolor)
|
tmpax[axissym][:grid](true, color = fgcolor)
|
||||||
tmpax[:set_axisbelow](true)
|
tmpax[:set_axisbelow](true)
|
||||||
@ -1169,20 +1206,20 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
# axis, scale, lims, ticks, flip, lab, rotation =
|
# axis, scale, lims, ticks, flip, lab, rotation =
|
||||||
# axis_symbols(letter, "axis", "scale", "lims", "ticks", "flip", "label", "rotation")
|
# axis_symbols(letter, "axis", "scale", "lims", "ticks", "flip", "label", "rotation")
|
||||||
# haskey(ax, axis) || continue
|
# haskey(ax, axis) || continue
|
||||||
# haskey(d, scale) && applyPyPlotScale(ax, d[scale], letter)
|
# haskey(spargs, scale) && applyPyPlotScale(ax, spargs[scale], letter)
|
||||||
# haskey(d, lims) && addPyPlotLims(ax, d[lims], letter)
|
# haskey(spargs, lims) && addPyPlotLims(ax, spargs[lims], letter)
|
||||||
# haskey(d, ticks) && addPyPlotTicks(ax, d[ticks], letter)
|
# haskey(spargs, ticks) && addPyPlotTicks(ax, spargs[ticks], letter)
|
||||||
# haskey(d, lab) && ax[symbol("set_", letter, "label")](d[lab])
|
# haskey(spargs, lab) && ax[symbol("set_", letter, "label")](spargs[lab])
|
||||||
# if get(d, flip, false)
|
# if get(spargs, flip, false)
|
||||||
# ax[symbol("invert_", letter, "axis")]()
|
# ax[symbol("invert_", letter, "axis")]()
|
||||||
# end
|
# end
|
||||||
# for tmpax in axes
|
# for tmpax in axes
|
||||||
# tmpax[axis][:label][:set_fontsize](guidesz)
|
# tmpax[axis][:label][:set_fontsize](guidesz)
|
||||||
# for lab in tmpax[symbol("get_", letter, "ticklabels")]()
|
# for lab in tmpax[symbol("get_", letter, "ticklabels")]()
|
||||||
# lab[:set_fontsize](ticksz)
|
# lab[:set_fontsize](ticksz)
|
||||||
# haskey(d, rotation) && lab[:set_rotation](d[rotation])
|
# haskey(spargs, rotation) && lab[:set_rotation](spargs[rotation])
|
||||||
# end
|
# end
|
||||||
# if get(d, :grid, false)
|
# if get(spargs, :grid, false)
|
||||||
# fgcolor = getPyPlotColor(plt.plotargs[:foreground_color_grid])
|
# fgcolor = getPyPlotColor(plt.plotargs[:foreground_color_grid])
|
||||||
# tmpax[axis][:grid](true, color = fgcolor)
|
# tmpax[axis][:grid](true, color = fgcolor)
|
||||||
# tmpax[:set_axisbelow](true)
|
# tmpax[:set_axisbelow](true)
|
||||||
@ -1191,7 +1228,7 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
# do we want to change the aspect ratio?
|
# do we want to change the aspect ratio?
|
||||||
aratio = get(d, :aspect_ratio, :none)
|
aratio = get(spargs, :aspect_ratio, :none)
|
||||||
if aratio != :none
|
if aratio != :none
|
||||||
ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C")
|
ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C")
|
||||||
end
|
end
|
||||||
@ -1367,7 +1404,6 @@ function finalizePlot(plt::Plot{PyPlotBackend})
|
|||||||
for asym in (:xaxis, :yaxis, :zaxis)
|
for asym in (:xaxis, :yaxis, :zaxis)
|
||||||
updateAxisColors(ax, sp.subplotargs[asym])
|
updateAxisColors(ax, sp.subplotargs[asym])
|
||||||
end
|
end
|
||||||
ax[:title][:set_color](getPyPlotColor(plt.plotargs[:titlefont].color))
|
|
||||||
end
|
end
|
||||||
drawfig(plt.o)
|
drawfig(plt.o)
|
||||||
plt.layout.bbox = py_bbox_fig(plt)
|
plt.layout.bbox = py_bbox_fig(plt)
|
||||||
|
|||||||
@ -52,7 +52,7 @@ function plot(args...; kw...)
|
|||||||
# to the backend to finish backend-specific initialization
|
# to the backend to finish backend-specific initialization
|
||||||
plt = Plot()
|
plt = Plot()
|
||||||
_update_plot_args(plt, d)
|
_update_plot_args(plt, d)
|
||||||
DD(plt.plotargs,"pargs")
|
# DD(plt.plotargs,"pargs")
|
||||||
plt.o = _create_backend_figure(plt)
|
plt.o = _create_backend_figure(plt)
|
||||||
|
|
||||||
# create the layout and subplots from the inputs
|
# create the layout and subplots from the inputs
|
||||||
@ -61,7 +61,7 @@ function plot(args...; kw...)
|
|||||||
# update the subplot/axis args from inputs, then pass to backend to init further
|
# update the subplot/axis args from inputs, then pass to backend to init further
|
||||||
sp.plt = plt
|
sp.plt = plt
|
||||||
_update_subplot_args(plt, sp, copy(d), idx)
|
_update_subplot_args(plt, sp, copy(d), idx)
|
||||||
DD(sp.subplotargs[:xaxis].d,"$idx")
|
# DD(sp.subplotargs[:xaxis].d,"$idx")
|
||||||
|
|
||||||
# TODO: i'd like to know what projection we're using by this point... can I push this off until later??
|
# TODO: i'd like to know what projection we're using by this point... can I push this off until later??
|
||||||
# I won't easily be able to auto-determine what series types are coming...
|
# I won't easily be able to auto-determine what series types are coming...
|
||||||
|
|||||||
@ -88,7 +88,7 @@ immutable SliceIt end
|
|||||||
|
|
||||||
# the catch-all recipes
|
# the catch-all recipes
|
||||||
@recipe function f(::Type{SliceIt}, x, y, z)
|
@recipe function f(::Type{SliceIt}, x, y, z)
|
||||||
@show "HERE", typeof((x,y,z))
|
# @show "HERE", typeof((x,y,z))
|
||||||
xs, _ = convertToAnyVector(x, d)
|
xs, _ = convertToAnyVector(x, d)
|
||||||
ys, _ = convertToAnyVector(y, d)
|
ys, _ = convertToAnyVector(y, d)
|
||||||
zs, _ = convertToAnyVector(z, d)
|
zs, _ = convertToAnyVector(z, d)
|
||||||
@ -111,9 +111,9 @@ immutable SliceIt end
|
|||||||
# add a new series
|
# add a new series
|
||||||
di = copy(d)
|
di = copy(d)
|
||||||
xi, yi, zi = xs[mod1(i,mx)], ys[mod1(i,my)], zs[mod1(i,mz)]
|
xi, yi, zi = xs[mod1(i,mx)], ys[mod1(i,my)], zs[mod1(i,mz)]
|
||||||
@show i, typeof((xi, yi, zi))
|
# @show i, typeof((xi, yi, zi))
|
||||||
di[:x], di[:y], di[:z] = compute_xyz(xi, yi, zi)
|
di[:x], di[:y], di[:z] = compute_xyz(xi, yi, zi)
|
||||||
@show i, typeof((di[:x], di[:y], di[:z]))
|
# @show i, typeof((di[:x], di[:y], di[:z]))
|
||||||
|
|
||||||
# handle fillrange
|
# handle fillrange
|
||||||
fr = fillranges[mod1(i,mf)]
|
fr = fillranges[mod1(i,mf)]
|
||||||
|
|||||||
@ -262,6 +262,15 @@ end
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
calc_num_subplots(layout::AbstractLayout) = 1
|
||||||
|
function calc_num_subplots(layout::GridLayout)
|
||||||
|
tot = 0
|
||||||
|
for l in layout.grid
|
||||||
|
tot += calc_num_subplots(l)
|
||||||
|
end
|
||||||
|
tot
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# pass the layout arg through
|
# pass the layout arg through
|
||||||
function build_layout(d::KW)
|
function build_layout(d::KW)
|
||||||
@ -286,8 +295,12 @@ end
|
|||||||
|
|
||||||
# compute number of subplots
|
# compute number of subplots
|
||||||
function build_layout(layout::GridLayout)
|
function build_layout(layout::GridLayout)
|
||||||
nr, nc = size(layout)
|
# nr, nc = size(layout)
|
||||||
build_layout(layout, nr*nc)
|
# build_layout(layout, nr*nc)
|
||||||
|
|
||||||
|
# recursively get the size of the grid
|
||||||
|
n = calc_num_subplots(layout)
|
||||||
|
build_layout(layout, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
# n is the number of subplots
|
# n is the number of subplots
|
||||||
@ -298,11 +311,22 @@ function build_layout(layout::GridLayout, n::Integer)
|
|||||||
i = 1
|
i = 1
|
||||||
for r=1:nr, c=1:nc
|
for r=1:nr, c=1:nc
|
||||||
i > n && break # only add n subplots
|
i > n && break # only add n subplots
|
||||||
sp = Subplot(backend(), parent=layout)
|
l = layout[r,c]
|
||||||
layout[r,c] = sp
|
if isa(l, EmptyLayout)
|
||||||
push!(subplots, sp)
|
sp = Subplot(backend(), parent=layout)
|
||||||
spmap[(r,c)] = sp
|
layout[r,c] = sp
|
||||||
i += 1
|
push!(subplots, sp)
|
||||||
|
spmap[length(subplots)] = sp
|
||||||
|
i += 1
|
||||||
|
elseif isa(l, GridLayout)
|
||||||
|
# sub-grid
|
||||||
|
l, sps, m = build_layout(l)
|
||||||
|
append!(subplots, sps)
|
||||||
|
for (k,v) in m
|
||||||
|
spmap[k+length(subplots)] = v
|
||||||
|
end
|
||||||
|
i += length(sps)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
layout, subplots, spmap
|
layout, subplots, spmap
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user