From 02a1e648bcd4b31800086fe65f35ecd7c61361c1 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 7 Mar 2016 15:17:29 -0500 Subject: [PATCH] added gr test; refactored pyplot figure generation, added overwrite_figure arg, closes #144 --- src/args.jl | 10 +++++++--- src/backends/pyplot.jl | 30 ++++++++++++++++++++++++------ src/backends/supported.jl | 3 ++- test/REQUIRE | 1 + test/runtests.jl | 7 +++++++ 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/args.jl b/src/args.jl index e9e55e9f..b9c537bd 100644 --- a/src/args.jl +++ b/src/args.jl @@ -179,14 +179,14 @@ _plotDefaults[:tickfont] = font(8) _plotDefaults[:guidefont] = font(11) _plotDefaults[:legendfont] = font(8) _plotDefaults[:grid] = true -_plotDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation) - +_plotDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation) +_plotDefaults[:overwrite_figure] = false # TODO: x/y scales const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults)))) -supportedArgs(::PlottingPackage) = _allArgs +supportedArgs(::PlottingPackage) = error("supportedArgs not defined") #_allArgs supportedArgs() = supportedArgs(backend()) @@ -307,6 +307,10 @@ end :palette => :color_palette, :xlink => :linkx, :ylink => :linky, + :clf => :overwrite_figure, + :clearfig => :overwrite_figure, + :overwrite => :overwrite_figure, + :reuse => :overwrite_figure, ) # add all pluralized forms to the _keyAliases dict diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 245803b2..e9b3023b 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -223,6 +223,24 @@ end # ------------------------------------------------------------------ +function pyplot_figure(plotargs::Dict) + w,h = map(px2inch, plotargs[:size]) + bgcolor = getPyPlotColor(plotargs[:background_color]) + fig = if plotargs[:overwrite_figure] + PyPlot.gcf() + else + PyPlot.figure() + end + fig[:set_size_inches](w,h,true) + fig[:set_facecolor](bgcolor) + fig[:set_dpi](DPI) + fig[:set_tight_layout](true) + PyPlot.clf() + PyPlot.plt[:get_current_fig_manager]()[:resize](plotargs[:size]...) + fig +end + + # TODO: # fillto # might have to use barHack/histogramHack?? # reg # true or false, add a regression line for each line @@ -239,9 +257,8 @@ function _create_plot(pkg::PyPlotPackage; kw...) if haskey(d, :subplot) wrap = nothing else - w,h = map(px2inch, d[:size]) - bgcolor = getPyPlotColor(d[:background_color]) - wrap = PyPlotAxisWrapper(nothing, nothing, PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true), []) + wrap = PyPlotAxisWrapper(nothing, nothing, pyplot_figure(d), []) + # wrap = PyPlotAxisWrapper(nothing, nothing, PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true), []) if haskey(d, :linetype) && first(d[:linetype]) in _3dTypes # && isa(plt.o, PyPlotFigWrapper) push!(wrap.kwargs, (:projection, "3d")) @@ -663,9 +680,10 @@ end function _create_subplot(subplt::Subplot{PyPlotPackage}, isbefore::Bool) l = subplt.layout - w,h = map(px2inch, getplotargs(subplt,1)[:size]) - bgcolor = getPyPlotColor(getplotargs(subplt,1)[:background_color]) - fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true) + # w,h = map(px2inch, getplotargs(subplt,1)[:size]) + # bgcolor = getPyPlotColor(getplotargs(subplt,1)[:background_color]) + # fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true) + fig = pyplot_figure(getplotargs(subplt, 1)) nr = nrows(l) for (i,(r,c)) in enumerate(l) diff --git a/src/backends/supported.jl b/src/backends/supported.jl index e1dadbed..36a2bae1 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -160,6 +160,7 @@ supportedArgs(::PyPlotPackage) = [ :fillalpha, :linealpha, :markeralpha, + :overwrite_figure, ] supportedAxes(::PyPlotPackage) = _allAxes supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, #:sticks, @@ -360,7 +361,7 @@ supportedArgs(::UnicodePlotsPackage) = [ # :z, ] supportedAxes(::UnicodePlotsPackage) = [:auto, :left] -supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline] +supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline] supportedStyles(::UnicodePlotsPackage) = [:auto, :solid] supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse] supportedScales(::UnicodePlotsPackage) = [:identity] diff --git a/test/REQUIRE b/test/REQUIRE index 17a29ad5..a2997f73 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -9,3 +9,4 @@ Images ImageMagick PyPlot @osx QuartzImageIO +GR diff --git a/test/runtests.jl b/test/runtests.jl index 4a691432..10387672 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,5 +26,12 @@ facts("PyPlot") do image_comparison_facts(:pyplot, skip=[4,10,13,19,21,23], eps=img_eps) end +facts("GR") do + @fact gr() --> Plots.GRPackage() + @fact backend() --> Plots.GRPackage() + + image_comparison_facts(:gr, only=[1], eps=img_eps) +end + FactCheck.exitstatus() end # module