working on fixing problems with subplots and contours
This commit is contained in:
parent
1604d867c3
commit
044d23f8a5
@ -654,7 +654,7 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
|
|||||||
# set label
|
# set label
|
||||||
label = d[:label]
|
label = d[:label]
|
||||||
label = (label == "AUTO" ? "y$globalIndex" : label)
|
label = (label == "AUTO" ? "y$globalIndex" : label)
|
||||||
if d[:axis] == :right && length(label) >= 4 && label[end-3:end] != " (R)"
|
if d[:axis] == :right && !(length(label) >= 4 && label[end-3:end] != " (R)")
|
||||||
label = string(label, " (R)")
|
label = string(label, " (R)")
|
||||||
end
|
end
|
||||||
d[:label] = label
|
d[:label] = label
|
||||||
|
|||||||
@ -153,13 +153,13 @@ end
|
|||||||
function plot(pkg::PyPlotPackage; kw...)
|
function plot(pkg::PyPlotPackage; kw...)
|
||||||
# create the figure
|
# create the figure
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
w,h = map(px2inch, d[:size])
|
|
||||||
bgcolor = getPyPlotColor(d[:background_color])
|
|
||||||
|
|
||||||
# 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)
|
||||||
wrap = nothing
|
wrap = nothing
|
||||||
else
|
else
|
||||||
|
w,h = map(px2inch, d[:size])
|
||||||
|
bgcolor = getPyPlotColor(d[:background_color])
|
||||||
wrap = PyPlotFigWrapper(PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96))
|
wrap = PyPlotFigWrapper(PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -257,9 +257,13 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
d[:serieshandle] = if lt == :hist
|
d[:serieshandle] = if lt == :hist
|
||||||
plotfunc(d[:y]; extra_kwargs...)[1]
|
plotfunc(d[:y]; extra_kwargs...)[1]
|
||||||
elseif lt == :contour
|
elseif lt == :contour
|
||||||
handle = plotfunc(d[:x], d[:y], d[:surface], d[:nlevels]; extra_kwargs...)
|
# NOTE: x/y are backwards in pyplot, so we switch the x and y args,
|
||||||
|
# and take the transpose of the surface matrix
|
||||||
|
x, y = d[:y], d[:x]
|
||||||
|
surf = d[:surface]'
|
||||||
|
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
|
||||||
if d[:fillrange] != nothing
|
if d[:fillrange] != nothing
|
||||||
handle = ax[:contourf](d[:x], d[:y], d[:surface], d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor]))
|
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor]))
|
||||||
end
|
end
|
||||||
handle
|
handle
|
||||||
elseif lt in (:scatter, :heatmap, :hexbin)
|
elseif lt in (:scatter, :heatmap, :hexbin)
|
||||||
@ -461,7 +465,7 @@ end
|
|||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
# create the underlying object (each backend will do this differently)
|
# NOTE: pyplot needs to build before
|
||||||
function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
|
function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
|
||||||
l = subplt.layout
|
l = subplt.layout
|
||||||
|
|
||||||
@ -484,6 +488,33 @@ function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool)
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# this will be called internally, when creating a subplot from existing plots
|
||||||
|
# NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use!
|
||||||
|
function subplot(plts::AVec{Plot{PyPlotPackage}}, layout::SubplotLayout, d::Dict)
|
||||||
|
validateSubplotSupported()
|
||||||
|
|
||||||
|
p = length(layout)
|
||||||
|
n = sum([plt.n for plt in plts])
|
||||||
|
|
||||||
|
pkg = PyPlotPackage()
|
||||||
|
newplts = Plot{PyPlotPackage}[plot(pkg; subplot=true, plt.initargs...) for plt in plts]
|
||||||
|
|
||||||
|
subplt = Subplot(nothing, newplts, PyPlotPackage(), p, n, layout, d, true, false, false, (r,c) -> (nothing,nothing))
|
||||||
|
|
||||||
|
preprocessSubplot(subplt, d)
|
||||||
|
buildSubplotObject!(subplt, true)
|
||||||
|
|
||||||
|
for (i,plt) in enumerate(plts)
|
||||||
|
for seriesargs in plt.seriesargs
|
||||||
|
_plot_from_subplot!(newplts[i]; seriesargs...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
postprocessSubplot(subplt, d)
|
||||||
|
|
||||||
|
subplt
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function handleLinkInner(plt::Plot{PyPlotPackage}, isx::Bool)
|
function handleLinkInner(plt::Plot{PyPlotPackage}, isx::Bool)
|
||||||
if isx
|
if isx
|
||||||
@ -517,13 +548,22 @@ function addPyPlotLegend(plt::Plot, ax)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function finalizePlot(plt::Plot{PyPlotPackage})
|
function finalizePlot(plt::Plot{PyPlotPackage})
|
||||||
wrap = plt.o
|
|
||||||
ax = getLeftAxis(plt)
|
ax = getLeftAxis(plt)
|
||||||
addPyPlotLegend(plt, ax)
|
addPyPlotLegend(plt, ax)
|
||||||
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
|
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
|
||||||
PyPlot.draw()
|
PyPlot.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function finalizePlot(subplt::Subplot{PyPlotPackage})
|
||||||
|
fig = subplt.o.fig
|
||||||
|
for (i,plt) in enumerate(subplt.plts)
|
||||||
|
ax = getLeftAxis(plt)
|
||||||
|
addPyPlotLegend(plt, ax)
|
||||||
|
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
|
||||||
|
end
|
||||||
|
PyPlot.draw()
|
||||||
|
end
|
||||||
|
|
||||||
# # allow for writing any supported mime
|
# # allow for writing any supported mime
|
||||||
# for mime in keys(PyPlot.aggformats)
|
# for mime in keys(PyPlot.aggformats)
|
||||||
# @eval function Base.writemime(io::IO, m::MIME{symbol{$mime}}, plt::Plot{PyPlotPackage})
|
# @eval function Base.writemime(io::IO, m::MIME{symbol{$mime}}, plt::Plot{PyPlotPackage})
|
||||||
@ -544,21 +584,16 @@ function Base.display(::PlotsDisplay, plt::PlottingObject{PyPlotPackage})
|
|||||||
if isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
if isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
||||||
display(getfig(plt.o))
|
display(getfig(plt.o))
|
||||||
else
|
else
|
||||||
PyPlot.ion()
|
# # PyPlot.ion()
|
||||||
PyPlot.figure(getfig(plt.o).o[:number])
|
# PyPlot.figure(getfig(plt.o).o[:number])
|
||||||
PyPlot.draw_if_interactive()
|
# PyPlot.draw_if_interactive()
|
||||||
PyPlot.ioff()
|
# # PyPlot.ioff()
|
||||||
end
|
end
|
||||||
|
# PyPlot.plt[:show](block=false)
|
||||||
|
getfig(plt.o)[:show]()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function finalizePlot(subplt::Subplot{PyPlotPackage})
|
|
||||||
fig = subplt.o.fig
|
|
||||||
for (i,plt) in enumerate(subplt.plts)
|
|
||||||
finalizePlot(plt)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotPackage})
|
# function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotPackage})
|
||||||
# finalizePlot(subplt)
|
# finalizePlot(subplt)
|
||||||
# PyPlot.ion()
|
# PyPlot.ion()
|
||||||
|
|||||||
@ -271,9 +271,9 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
|
|||||||
# build the series arg dict
|
# build the series arg dict
|
||||||
numUncounted = get(d, :numUncounted, 0)
|
numUncounted = get(d, :numUncounted, 0)
|
||||||
n = plt.n + i + numUncounted
|
n = plt.n + i + numUncounted
|
||||||
dumpdict(d, "before getSeriesArgs")
|
# dumpdict(d, "before getSeriesArgs")
|
||||||
d = getSeriesArgs(plt.backend, getinitargs(plt, n), d, i + numUncounted, convertSeriesIndex(plt, n), n)
|
d = getSeriesArgs(plt.backend, getinitargs(plt, n), d, i + numUncounted, convertSeriesIndex(plt, n), n)
|
||||||
dumpdict(d, "after getSeriesArgs")
|
# dumpdict(d, "after getSeriesArgs")
|
||||||
d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)])
|
d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)])
|
||||||
|
|
||||||
if haskey(d, :idxfilter)
|
if haskey(d, :idxfilter)
|
||||||
|
|||||||
@ -14,15 +14,23 @@ export
|
|||||||
immerse,
|
immerse,
|
||||||
pyplot,
|
pyplot,
|
||||||
qwt,
|
qwt,
|
||||||
unicodeplots,
|
unicodeplots
|
||||||
winston
|
# winston
|
||||||
|
|
||||||
gadfly() = backend(:gadfly)
|
gadfly() = backend(:gadfly)
|
||||||
immerse() = backend(:immerse)
|
immerse() = backend(:immerse)
|
||||||
pyplot() = backend(:pyplot)
|
pyplot() = backend(:pyplot)
|
||||||
qwt() = backend(:qwt)
|
qwt() = backend(:qwt)
|
||||||
unicodeplots() = backend(:unicodeplots)
|
unicodeplots() = backend(:unicodeplots)
|
||||||
winston() = backend(:winston)
|
# winston() = backend(:winston)
|
||||||
|
|
||||||
|
const _backendNames = Dict(
|
||||||
|
GadflyPackage() => :gadfly,
|
||||||
|
ImmersePackage() => :immerse,
|
||||||
|
PyPlotPackage() => :pyplot,
|
||||||
|
QwtPackage() => :qwt,
|
||||||
|
UnicodePlotsPackage() => :unicodeplots,
|
||||||
|
)
|
||||||
|
|
||||||
include("backends/supported.jl")
|
include("backends/supported.jl")
|
||||||
|
|
||||||
@ -211,8 +219,13 @@ function backend()
|
|||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots
|
Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots, :immerse, :pyplot
|
||||||
"""
|
"""
|
||||||
|
function backend(pkg::PlottingPackage)
|
||||||
|
CURRENT_BACKEND.sym = _backendNames(pkg)
|
||||||
|
CURRENT_BACKEND.pkg = pkg
|
||||||
|
end
|
||||||
|
|
||||||
function backend(modname)
|
function backend(modname)
|
||||||
|
|
||||||
# set the PlottingPackage
|
# set the PlottingPackage
|
||||||
|
|||||||
@ -349,6 +349,7 @@ function subplot!(subplt::Subplot, args...; kw...)
|
|||||||
|
|
||||||
subplt.n += 1
|
subplt.n += 1
|
||||||
plt = getplot(subplt)
|
plt = getplot(subplt)
|
||||||
|
plt.n += 1
|
||||||
|
|
||||||
# # update the plot's initargs for things such as palettes, etc
|
# # update the plot's initargs for things such as palettes, etc
|
||||||
# for (k,v) in subplt.initargs
|
# for (k,v) in subplt.initargs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user