This commit is contained in:
Thomas Breloff 2015-09-23 11:35:08 -04:00
parent 273996aa91
commit 80e8b5b5e4
3 changed files with 21 additions and 4 deletions

View File

@ -107,7 +107,15 @@ function updateAxisColors(ax, fgcolor)
ax[:title][:set_color](fgcolor) ax[:title][:set_color](fgcolor)
end end
nop() = nothing
# makePyPlotCurrent(plt::Plot) = PyPlot.withfig(nop, plt.o[1])
makePyPlotCurrent(plt::Plot) = PyPlot.figure(plt.o[1].o[:number]) makePyPlotCurrent(plt::Plot) = PyPlot.figure(plt.o[1].o[:number])
# makePyPlotCurrent(plt::Plot) = PyPlot.orig_figure(num = plt.o[1].o[:number])
function preparePlotUpdate(plt::Plot{PyPlotPackage})
makePyPlotCurrent(plt)
end
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@ -139,7 +147,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
fig, num = plt.o fig, num = plt.o
# PyPlot.figure(num) # makes this current # PyPlot.figure(num) # makes this current
makePyPlotCurrent(plt) # makePyPlotCurrent(plt)
if !(d[:linetype] in supportedTypes(pkg)) if !(d[:linetype] in supportedTypes(pkg))
error("linetype $(d[:linetype]) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))") error("linetype $(d[:linetype]) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))")
@ -218,7 +226,7 @@ end
function updatePlotItems(plt::Plot{PyPlotPackage}, d::Dict) function updatePlotItems(plt::Plot{PyPlotPackage}, d::Dict)
makePyPlotCurrent(plt) # makePyPlotCurrent(plt)
haskey(d, :title) && PyPlot.title(d[:title]) haskey(d, :title) && PyPlot.title(d[:title])
haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel]) haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel])
if haskey(d, :ylabel) if haskey(d, :ylabel)
@ -266,7 +274,10 @@ end
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{PyPlotPackage}) function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{PyPlotPackage})
fig, num = plt.o fig, num = plt.o
# makePyPlotCurrent(plt)
addPyPlotLegend(plt) addPyPlotLegend(plt)
ax = fig.o[:axes][1]
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))
writemime(io, m, fig) writemime(io, m, fig)
end end
@ -274,7 +285,7 @@ end
function Base.display(::PlotsDisplay, plt::Plot{PyPlotPackage}) function Base.display(::PlotsDisplay, plt::Plot{PyPlotPackage})
fig, num = plt.o fig, num = plt.o
# PyPlot.figure(num) # makes this current # PyPlot.figure(num) # makes this current
makePyPlotCurrent(plt) # makePyPlotCurrent(plt)
addPyPlotLegend(plt) addPyPlotLegend(plt)
ax = fig.o[:axes][1] ax = fig.o[:axes][1]
updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color])) updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color]))

View File

@ -87,6 +87,9 @@ function plot!(plt::Plot, args...; kw...)
# Ideally we don't change the insides ot createKWargsList too much to # Ideally we don't change the insides ot createKWargsList too much to
# save from code repetition. We could consider adding a throw # save from code repetition. We could consider adding a throw
# just in case the backend needs to set up the plot (make it current or something)
preparePlotUpdate(plt)
kwList = createKWargsList(plt, args...; d...) kwList = createKWargsList(plt, args...; d...)
for (i,d) in enumerate(kwList) for (i,d) in enumerate(kwList)
plt.n += 1 plt.n += 1
@ -105,6 +108,8 @@ function plot!(plt::Plot, args...; kw...)
plt plt
end end
preparePlotUpdate(plt::Plot) = nothing
# # show/update the plot # # show/update the plot
# function Base.display(plt::PlottingObject) # function Base.display(plt::PlottingObject)
# display(plt.plotter, plt) # display(plt.plotter, plt)
@ -195,7 +200,7 @@ function createKWargsList(plt::PlottingObject, f::FuncOrFuncs; kw...)
end end
function createKWargsList(plt::PlottingObject, f::FuncOrFuncs, x; kw...) function createKWargsList(plt::PlottingObject, f::FuncOrFuncs, x; kw...)
@assert !(x <: FuncOrFuncs) # otherwise we'd hit infinite recursion here @assert !(typeof(x) <: FuncOrFuncs) # otherwise we'd hit infinite recursion here
createKWargsList(plt, x, f; kw...) createKWargsList(plt, x, f; kw...)
end end

View File

@ -179,6 +179,7 @@ function plotter!(modname)
# update the symbol # update the symbol
CURRENT_BACKEND.sym = modname CURRENT_BACKEND.sym = modname
println("[Plots.jl] Switched to backend: ", modname)
# return the package # return the package
CURRENT_BACKEND.pkg CURRENT_BACKEND.pkg