From 80e8b5b5e4a0fe96193f2052fb477908b1503597 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Wed, 23 Sep 2015 11:35:08 -0400 Subject: [PATCH] fixes --- src/backends/pyplot.jl | 17 ++++++++++++++--- src/plot.jl | 7 ++++++- src/plotter.jl | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 0529c575..8ff8d914 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -107,7 +107,15 @@ function updateAxisColors(ax, fgcolor) ax[:title][:set_color](fgcolor) 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.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 # PyPlot.figure(num) # makes this current - makePyPlotCurrent(plt) + # makePyPlotCurrent(plt) if !(d[:linetype] in 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) - makePyPlotCurrent(plt) + # makePyPlotCurrent(plt) haskey(d, :title) && PyPlot.title(d[:title]) haskey(d, :xlabel) && PyPlot.xlabel(d[:xlabel]) if haskey(d, :ylabel) @@ -266,7 +274,10 @@ end function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{PyPlotPackage}) fig, num = plt.o + # makePyPlotCurrent(plt) addPyPlotLegend(plt) + ax = fig.o[:axes][1] + updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color])) writemime(io, m, fig) end @@ -274,7 +285,7 @@ end function Base.display(::PlotsDisplay, plt::Plot{PyPlotPackage}) fig, num = plt.o # PyPlot.figure(num) # makes this current - makePyPlotCurrent(plt) + # makePyPlotCurrent(plt) addPyPlotLegend(plt) ax = fig.o[:axes][1] updateAxisColors(ax, getPyPlotColor(plt.initargs[:foreground_color])) diff --git a/src/plot.jl b/src/plot.jl index d6a8e613..a8a82fff 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -87,6 +87,9 @@ function plot!(plt::Plot, args...; kw...) # Ideally we don't change the insides ot createKWargsList too much to # 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...) for (i,d) in enumerate(kwList) plt.n += 1 @@ -105,6 +108,8 @@ function plot!(plt::Plot, args...; kw...) plt end +preparePlotUpdate(plt::Plot) = nothing + # # show/update the plot # function Base.display(plt::PlottingObject) # display(plt.plotter, plt) @@ -195,7 +200,7 @@ function createKWargsList(plt::PlottingObject, f::FuncOrFuncs; kw...) end 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...) end diff --git a/src/plotter.jl b/src/plotter.jl index dcf97b7e..4a1b5cb6 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -179,6 +179,7 @@ function plotter!(modname) # update the symbol CURRENT_BACKEND.sym = modname + println("[Plots.jl] Switched to backend: ", modname) # return the package CURRENT_BACKEND.pkg