diff --git a/src/args.jl b/src/args.jl index b655863e..9d718559 100644 --- a/src/args.jl +++ b/src/args.jl @@ -199,7 +199,7 @@ _plotDefaults[:size] = (600,400) _plotDefaults[:pos] = (0,0) _plotDefaults[:windowtitle] = "Plots.jl" _plotDefaults[:show] = false -_plotDefaults[:layout] = nothing +_plotDefaults[:layout] = :auto _plotDefaults[:n] = -1 _plotDefaults[:nr] = -1 _plotDefaults[:nc] = -1 diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 3370e3e0..3b040d95 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -35,6 +35,7 @@ supportedArgs(::PyPlotBackend) = [ :polar, :normalize, :weights, :contours, :aspect_ratio, :match_dimensions, + :subplot, ] supportedAxes(::PyPlotBackend) = _allAxes supportedTypes(::PyPlotBackend) = [ @@ -333,7 +334,8 @@ end # each backend should set up the subplot here function _initialize_subplot(plt::Plot{PyPlotBackend}, sp::Subplot{PyPlotBackend}) fig = plt.o - ax = fig[:add_axes]([0,0,1,1]) + # add a new axis, and force it to create a new one by setting a distinct label + ax = fig[:add_axes]([0,0,1,1], label = string(gensym())) for axis in (:xaxis, :yaxis) ax[axis][:_autolabelpos] = false end diff --git a/src/plot.jl b/src/plot.jl index 0fa292d7..3f3814ef 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -60,7 +60,9 @@ function plot(args...; kw...) plt.layout, plt.subplots, plt.spmap = build_layout(pop!(d, :layout, :auto)) for sp in plt.subplots + @show sp.o _initialize_subplot(plt, sp) + @show sp.o end # now update the plot @@ -275,12 +277,12 @@ function _plot!(plt::Plot, d::KW, args...) # merge plot args... this is where we combine all the plot args from the user and # from the recipes... axis info, colors, etc # TODO: why do i need to check for the subplot key? - if !haskey(d, :subplot) + # if !haskey(d, :subplot) for kw in vcat(kw_list, d) _add_plotargs!(plt, kw) end handlePlotColors(plt.backend, plt.plotargs) - end + # end # for kw in kw_list # @show typeof((kw[:x], kw[:y], kw[:z])) @@ -334,10 +336,10 @@ function _plot!(plt::Plot, d::KW, args...) # add title, axis labels, ticks, etc # TODO: do we really need this subplot check? - if !haskey(d, :subplot) + # if !haskey(d, :subplot) # merge!(plt.plotargs, d) # this shouldn't be needed since we merged the keys earlier _update_plot(plt, plt.plotargs) - end + # end current(plt) diff --git a/src/series_new.jl b/src/series_new.jl index 07752e40..36d2f2fc 100644 --- a/src/series_new.jl +++ b/src/series_new.jl @@ -14,9 +14,9 @@ function _add_defaults!(d::KW, plt::Plot, commandIndex::Int) setDictValue(d, d, k, commandIndex, _seriesDefaults) end - if d[:subplot_index] == :auto + if d[:subplot] == :auto # TODO: something useful - d[:subplot_index] = 1 + d[:subplot] = 1 end aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex) @@ -66,7 +66,7 @@ function _add_defaults!(d::KW, plt::Plot, commandIndex::Int) label = string(label, " (R)") end d[:label] = label - + d end diff --git a/src/subplots.jl b/src/subplots.jl index 4042ecc1..ae21be79 100644 --- a/src/subplots.jl +++ b/src/subplots.jl @@ -149,16 +149,22 @@ function update_bboxes!(layout::GridLayout) #, parent_bbox::BoundingBox = Boundi # TODO: this should really track used/free space for each row/column so that we can align plot areas properly - l, b = 0.0, 0.0 + # l, b = 0.0, 0.0 + rights = zeros(nc) + tops = zeros(nr) for r=1:nr, c=1:nc # compute the child's bounding box relative to the parent child = layout[r,c] usedw, usedh = used_size(child) - child_bbox = BoundingBox( - l, b, - l + usedw + freew * layout.widths[c], - b + usedh + freeh * layout.heights[r] - ) + + left = (c == 1 ? 0 : rights[c-1]) + bottom = (r == 1 ? 0 : tops[r-1]) + right = left + usedw + freew * layout.widths[c] + top = bottom + usedh + freeh * layout.heights[r] + child_bbox = BoundingBox(left, bottom, right, top) + + rights[c] = right + tops[r] = top # then compute the bounding box relative to the canvas, and cache it in the child object bbox!(child, crop(bbox(layout), child_bbox))