added gr test; refactored pyplot figure generation, added overwrite_figure arg, closes #144

This commit is contained in:
Thomas Breloff 2016-03-07 15:17:29 -05:00
parent 9d3e0651e2
commit 02a1e648bc
5 changed files with 41 additions and 10 deletions

View File

@ -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

View File

@ -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)

View File

@ -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]

View File

@ -9,3 +9,4 @@ Images
ImageMagick
PyPlot
@osx QuartzImageIO
GR

View File

@ -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