From e58fb935b020d631b06db27dfdecb5b6838793f0 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 27 Oct 2015 19:25:27 -0400 Subject: [PATCH] several fixes, plus qwt pos/size --- src/backends/gadfly.jl | 7 ++++--- src/backends/pyplot.jl | 4 ++-- src/backends/qwt.jl | 13 +++++++++---- src/plot.jl | 9 ++++++--- src/plotter.jl | 17 +++++++++-------- src/subplot.jl | 2 ++ 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 6f5df7e6..923d8f93 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -76,9 +76,10 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...) gfargs = vcat(geoms..., getGadflyLineTheme(d)) kwargs = Dict() + lt = d[:linetype] # add a fill? - if d[:fillrange] != nothing + if d[:fillrange] != nothing && lt != :contour fillmin, fillmax = map(makevec, maketuple(d[:fillrange])) nmin, nmax = length(fillmin), length(fillmax) kwargs[:ymin] = Float64[min(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(d[:y])] @@ -87,7 +88,6 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...) end # h/vlines - lt = d[:linetype] if lt == :hline kwargs[:yintercept] = d[:y] elseif lt == :vline @@ -97,6 +97,7 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...) kwargs[:xmin] = d[:x] - w kwargs[:xmax] = d[:x] + w elseif lt == :contour + d[:y] = reverse(d[:y]) kwargs[:z] = d[:surface] end @@ -176,7 +177,7 @@ function addToGadflyLegend(plt::Plot, d::Dict) # extend the label if we found this color for i in 1:length(guide.colors) - if c == guide.colors[i] + if RGB(c) == guide.colors[i] guide.labels[i] *= ", " * d[:label] foundit = true end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index cc9c09bf..ba0c7aeb 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -257,9 +257,9 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...) d[:serieshandle] = if lt == :hist plotfunc(d[:y]; extra_kwargs...)[1] elseif lt == :contour - # NOTE: x/y are backwards in pyplot, so we switch the x and y args, + # NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed), # and take the transpose of the surface matrix - x, y = d[:y], d[:x] + x, y = reverse(d[:y]), d[:x] surf = d[:surface]' handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...) if d[:fillrange] != nothing diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index a381cf03..aa41859b 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -139,6 +139,11 @@ function updatePlotItems(plt::Plot{QwtPackage}, d::Dict) updateLimsAndTicks(plt, d, false) end +function updatePositionAndSize(plt::PlottingObject{QwtPackage}, d::Dict) + haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...) + haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...) +end + # ---------------------------------------------------------------- @@ -266,10 +271,10 @@ function Base.display(::PlotsDisplay, subplt::Subplot{QwtPackage}) for plt in subplt.plts Qwt.refresh(plt.o) end - iargs = getinitargs(subplt,1) - # iargs = subplt.initargs - Qwt.resizewidget(subplt.o, iargs[:size]...) - Qwt.movewidget(subplt.o, iargs[:pos]...) + # iargs = getinitargs(subplt,1) + # # iargs = subplt.initargs + # Qwt.resizewidget(subplt.o, iargs[:size]...) + # Qwt.movewidget(subplt.o, iargs[:pos]...) Qwt.showwidget(subplt.o) end diff --git a/src/plot.jl b/src/plot.jl index d8fc738d..424663f4 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -121,10 +121,13 @@ function plot!(plt::Plot, args...; kw...) # add title, axis labels, ticks, etc if !haskey(d, :subplot) - d = merge!(plt.initargs, d) - dumpdict(d, "Updating plot items") - updatePlotItems(plt, d) + merge!(plt.initargs, d) + dumpdict(plt.initargs, "Updating plot items") + updatePlotItems(plt, plt.initargs) end + + updatePositionAndSize(plt, d) + current(plt) # NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement diff --git a/src/plotter.jl b/src/plotter.jl index c1dea79c..1d147e4b 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -24,13 +24,11 @@ qwt() = backend(:qwt) unicodeplots() = backend(:unicodeplots) # winston() = backend(:winston) -const _backendNames = Dict( - GadflyPackage() => :gadfly, - ImmersePackage() => :immerse, - PyPlotPackage() => :pyplot, - QwtPackage() => :qwt, - UnicodePlotsPackage() => :unicodeplots, - ) +backend_name(::GadflyPackage) = :gadfly +backend_name(::ImmersePackage) = :immerse +backend_name(::PyPlotPackage) = :pyplot +backend_name(::UnicodePlotsPackage) = :unicodeplots +backend_name(::QwtPackage) = :qwt include("backends/supported.jl") @@ -50,6 +48,8 @@ plot!(pkg::PlottingPackage, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) i updatePlotItems(pkg::PlottingPackage, plt::Plot, d::Dict) = error("updatePlotItems($pkg, plt, d) is not implemented") # Base.display(pkg::PlottingPackage, plt::Plot) = error("display($pkg, plt) is not implemented") +updatePositionAndSize{P<:PlottingPackage}(plt::PlottingObject{P}, d::Dict) = nothing #error("updatePositionAndSize(plt,d) is not implemented for $P") + subplot(pkg::PlottingPackage; kw...) = error("subplot($pkg; kw...) is not implemented") subplot!(pkg::PlottingPackage, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented") # Base.display(pkg::PlottingPackage, subplt::Subplot) = error("display($pkg, subplt) is not implemented") @@ -222,7 +222,8 @@ end Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots, :immerse, :pyplot """ function backend(pkg::PlottingPackage) - CURRENT_BACKEND.sym = _backendNames(pkg) + + CURRENT_BACKEND.sym = backend_name(pkg) CURRENT_BACKEND.pkg = pkg end diff --git a/src/subplot.jl b/src/subplot.jl index cbf6a798..b4d3639f 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -289,6 +289,8 @@ function postprocessSubplot(subplt::Subplot, d::Dict) updatePlotItems(plt, di) end + updatePositionAndSize(subplt, d) + # handle links subplt.linkx && linkAxis(subplt, true) subplt.linky && linkAxis(subplt, false)