pyplot subplots

This commit is contained in:
Thomas Breloff 2015-10-13 15:30:25 -04:00
parent 09fceab75b
commit 8fdbbe4c16
2 changed files with 72 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@ -227,10 +227,8 @@ function plot(pkg::PyPlotPackage; kw...)
# standalone plots will create a figure, but not if part of a subplot (do it later) # standalone plots will create a figure, but not if part of a subplot (do it later)
if haskey(d, :subplot) if haskey(d, :subplot)
println("no wrap")
wrap = nothing wrap = nothing
else else
println("yes wrap")
wrap = PyPlotFigWrapper(PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96)) wrap = PyPlotFigWrapper(PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96))
end end
@ -444,28 +442,44 @@ end
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool) function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
l = subplt.layout l = subplt.layout
isa(l, GridLayout) || error("Unsupported layout ", l)
iargs = subplt.initargs[1] w,h = map(px2inch, subplt.initargs[1][:size])
w,h = map(px2inch, iargs[:size]) bgcolor = getPyPlotColor(subplt.initargs[1][:background_color])
bgcolor = getPyPlotColor(iargs[:background_color]) fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96)
n, m = nrows(l), ncols(l)
fig, axes = PyPlot.subplots(n, m,
sharex = get(iargs,:linkx,false),
sharey = get(iargs,:linky,false),
figsize = (w,h),
facecolor = bgcolor,
dpi = 96)
# @show axes nr = nrows(l)
@assert length(axes) == length(subplt.plts) for (i,(r,c)) in enumerate(l)
axes = vec(reshape(axes, n, m)') # add the plot to the figure
nc = ncols(l, r)
fakeidx = (r-1) * nc + c
ax = fig[:add_subplot](nr, nc, fakeidx)
for (i,plt) in enumerate(subplt.plts) subplt.plts[i].o = PyPlotAxisWrapper(ax)
plt.o = PyPlotAxisWrapper(axes[i])
end end
# isa(l, GridLayout) || error("Unsupported layout ", l)
# iargs = subplt.initargs[1]
# w,h = map(px2inch, iargs[:size])
# bgcolor = getPyPlotColor(iargs[:background_color])
# n, m = nrows(l), ncols(l)
# fig, axes = PyPlot.subplots(n, m,
# sharex = get(iargs,:linkx,false),
# sharey = get(iargs,:linky,false),
# figsize = (w,h),
# facecolor = bgcolor,
# dpi = 96)
# # @show axes
# @assert length(axes) == length(subplt.plts)
# axes = vec(reshape(axes, n, m)')
# for (i,plt) in enumerate(subplt.plts)
# plt.o = PyPlotAxisWrapper(axes[i])
# end
# @show fig axes # @show fig axes
subplt.o = PyPlotFigWrapper(fig) subplt.o = PyPlotFigWrapper(fig)
true true
@ -478,6 +492,45 @@ function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
# # return wrap.fig.o[:add_subplot](111) # # return wrap.fig.o[:add_subplot](111)
end end
# # create the underlying object (each backend will do this differently)
# function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
# l = subplt.layout
# isa(l, GridLayout) || error("Unsupported layout ", l)
# iargs = subplt.initargs[1]
# w,h = map(px2inch, iargs[:size])
# bgcolor = getPyPlotColor(iargs[:background_color])
# n, m = nrows(l), ncols(l)
# fig, axes = PyPlot.subplots(n, m,
# sharex = get(iargs,:linkx,false),
# sharey = get(iargs,:linky,false),
# figsize = (w,h),
# facecolor = bgcolor,
# dpi = 96)
# # @show axes
# @assert length(axes) == length(subplt.plts)
# axes = vec(reshape(axes, n, m)')
# for (i,plt) in enumerate(subplt.plts)
# plt.o = PyPlotAxisWrapper(axes[i])
# end
# # @show fig axes
# subplt.o = PyPlotFigWrapper(fig)
# true
# # # TODO: set plt.o = PyPlotAxisWrapper(ax) for each plot
# # for (i,(r,c)) in enumerate(subplt.layout)
# # plt = subplt.plts[i]
# # plt.o = PyPlotAxisWrapper(subplt.o.fig.o[:add_subplot]())
# # # return wrap.fig.o[:add_subplot](111)
# end
function handleLinkInner(plt::Plot{PyPlotPackage}, isx::Bool) function handleLinkInner(plt::Plot{PyPlotPackage}, isx::Bool)
if isx if isx
plot!(plt, xticks=zeros(0), xlabel="") plot!(plt, xticks=zeros(0), xlabel="")