From b9818a4480356df4e74994b38581df8e672c95d7 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 22 Apr 2016 10:44:12 -0400 Subject: [PATCH] working on seriescolor and pyplot reorgs --- src/args.jl | 50 +++++++++--- src/backends/pyplot.jl | 160 ++++++++++++++++++++++---------------- src/backends/supported.jl | 10 +-- 3 files changed, 137 insertions(+), 83 deletions(-) diff --git a/src/args.jl b/src/args.jl index 0526df77..13cd004d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -252,6 +252,7 @@ end :width => :linewidth, :lw => :linewidth, :la => :linealpha, + :lalpha => :linealpha, :lineopacity => :linealpha, :type => :linetype, :lt => :linetype, @@ -280,6 +281,7 @@ end :fcolor => :fillcolor, :fillcolour => :fillcolor, :fa => :fillalpha, + :falpha => :fillalpha, :fillopacity => :fillalpha, :g => :group, :nb => :nbins, @@ -794,25 +796,49 @@ function getSeriesArgs(pkg::AbstractBackend, plotargs::KW, kw, commandIndex::Int # update color d[:seriescolor] = getSeriesRGBColor(d[:seriescolor], plotargs, plotIndex) - # update linecolor - c = d[:linecolor] - c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) - d[:linecolor] = c + # # update linecolor + # c = d[:linecolor] + # c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) + # d[:linecolor] = c - # update markercolor - c = d[:markercolor] - c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) - d[:markercolor] = c + # # update markercolor + # c = d[:markercolor] + # c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) + # d[:markercolor] = c + + # # update fillcolor + # c = d[:fillcolor] + # c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) + # d[:fillcolor] = c + + # update colors + for csym in (:linecolor, :markercolor, :fillcolor) + d[csym] = if d[csym] == :match + d[:seriescolor] + else + getSeriesRGBColor(d[csym], plotargs, plotIndex) + end + end # update markerstrokecolor c = d[:markerstrokecolor] c = (c == :match ? plotargs[:foreground_color] : getSeriesRGBColor(c, plotargs, plotIndex)) d[:markerstrokecolor] = c - # update fillcolor - c = d[:fillcolor] - c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) - d[:fillcolor] = c + # update alphas + for asym in (:linealpha, :markeralpha, :fillalpha) + if d[asym] == nothing + d[asym] = d[:seriesalpha] + end + end + + # scatter plots don't have a line, but must have a shape + if d[:linetype] in (:scatter, :scatter3d) + d[:linewidth] = 0 + if d[:markershape] == :none + d[:markershape] = :ellipse + end + end # set label label = d[:label] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 1b937eff..e8f690ac 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -294,37 +294,53 @@ function fix_xy_lengths!(plt::Plot{PyPlotBackend}, d::KW) end end -# figure out the extra kw from zcolor in scatter and scatter3d -function get_extra_kw(plt::Plot{PyPlotBackend}, d::KW) - extra_kw = KW() - if d[:linetype] in (:scatter, :scatter3d) - c = getPyPlotColor(d[:markercolor]) - if d[:marker_z] == nothing - c = getPyPlotColor(c, d[:markeralpha]) +# # figure out the extra kw from zcolor in scatter and scatter3d +# function get_extra_kw(plt::Plot{PyPlotBackend}, d::KW) +# extra_kw = KW() +# if d[:linetype] in (:scatter, :scatter3d) +# c = getPyPlotColor(d[:markercolor]) +# if d[:marker_z] == nothing +# c = getPyPlotColor(c, d[:markeralpha]) +# +# # total hack due to PyPlot bug (see issue #145). +# # hack: duplicate the color vector when the total rgba fields is the same as the series length +# if (typeof(c) <: AbstractArray && length(c)*4 == length(x)) || (typeof(c) <: Tuple && length(x) == 4) +# c = vcat(c, c) +# end +# extra_kw[:c] = c +# else +# if !isa(c, ColorGradient) +# c = default_gradient() +# end +# extra_kw[:c] = convert(Vector{Float64}, d[:marker_z]) +# extra_kw[:cmap] = getPyPlotColorMap(c, d[:markeralpha]) +# end +# end +# extra_kw +# end +# +# function get_cmap(plt::Plot{PyPlotBackend}, d::KW) +# +# end - # total hack due to PyPlot bug (see issue #145). - # hack: duplicate the color vector when the total rgba fields is the same as the series length - if (typeof(c) <: AbstractArray && length(c)*4 == length(x)) || (typeof(c) <: Tuple && length(x) == 4) - c = vcat(c, c) - end - extra_kw[:c] = c - else - if !isa(c, ColorGradient) - c = default_gradient() - end - extra_kw[:c] = convert(Vector{Float64}, d[:marker_z]) - extra_kw[:cmap] = getPyPlotColorMap(c, d[:markeralpha]) - end +# total hack due to PyPlot bug (see issue #145). +# hack: duplicate the color vector when the total rgba fields is the same as the series length +function color_fix(c) + if (typeof(c) <: AbstractArray && length(c)*4 == length(x)) || + (typeof(c) <: Tuple && length(x) == 4) + vcat(c, c) + else + c end - extra_kw end -function get_cmap(plt::Plot{PyPlotBackend}, d::KW) +pylinecolor(d::KW) = getPyPlotColor(d[:linecolor], d[:linealpha]) +pymarkercolor(d::KW) = getPyPlotColor(d[:markercolor], d[:markeralpha]) +pymarkercolormap(d::KW) = getPyPlotColorMap(d[:markercolor], d[:markeralpha]) +pymarkerstrokecolor(d::KW) = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha]) +pyfillcolor(d::KW) = getPyPlotColor(d[:fillcolor], d[:fillalpha]) -end - - -function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) +function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) lt = d[:linetype] if !(lt in supportedTypes(pkg)) error("linetype $(lt) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))") @@ -339,24 +355,27 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) fix_xy_lengths!(plt, d) ax = getAxis(plt, d[:axis]) - linecolor = getPyPlotColor(d[:linecolor], d[:linealpha]) - markercolor = if d[:marker_z] == nothing - getPyPlotColor(d[:markercolor], d[:markeralpha]) - else - getPyPlotColorMap(d[:markercolor], d[:markeralpha]) - end - fillcolor = getPyPlotColor(d[:fillcolor], d[:fillalpha]) - strokecolor = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha]) + # linecolor = getPyPlotColor(d[:linecolor], d[:linealpha]) + # markercolor = if d[:marker_z] == nothing + # getPyPlotColor(d[:markercolor], d[:markeralpha]) + # else + # getPyPlotColorMap(d[:markercolor], d[:markeralpha]) + # end + # fillcolor = getPyPlotColor(d[:fillcolor], d[:fillalpha]) + # strokecolor = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha]) # linecmap = getPyPlotColorMap(d[:linecolor], d[:linealpha]) # fillcmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]) - linestyle = getPyPlotLineStyle(lt, d[:linestyle]) - markershape = getPyPlotMarker(d[:markershape]) + # linestyle = getPyPlotLineStyle(lt, d[:linestyle]) + # markershape = getPyPlotMarker(d[:markershape]) x, y, z = d[:x], d[:y], d[:z] - cmap = get_cmap(plt, d) + # cmap = get_cmap(plt, d) + + dumpdict(d, "",true) # handle zcolor and get c/cmap - extra_kw = get_extra_kw(plt, d) + # extra_kw = get_extra_kw(plt, d) + extrakw = KW() # :hist => :hist, # :density => :hist, @@ -373,39 +392,48 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) # :shape => :add_patch, # # do the plotting - if lt in (:path, :line) - ax[:plot](x, y; - color = linecolor, - linewidth = linewidth, - linestyle = linestyle, - drawstyle = getPyPlotStepStyle(lt), - marker = markershape, - markersize = d[:markersize], - markerfacecolor = markercolor, - markeredgecolor = strokecolor, - markeredgewidth = d[:markerstrokewidth], - label = d[:label], - zorder = plt.n - ) - elseif lt == :scatter - ax[:plot](x, y; - linewidth = 0, - marker = markershape, - markersize = d[:markersize], - markerfacecolor = markercolor, - markeredgecolor = strokecolor, - markeredgewidth = d[:markerstrokewidth], - label = d[:label], - zorder = plt.n, - extra_kw... - ) + if lt in (:path, :line, :scatter) + if d[:linewidth] > 0 + d[:serieshandle] = ax[:plot](x, y; + color = pylinecolor(d), + linewidth = d[:linewidth], + linestyle = getPyPlotLineStyle(lt, d[:linestyle]), + drawstyle = getPyPlotStepStyle(lt), + # marker = markershape, + # markersize = d[:markersize], + # markerfacecolor = markercolor, + # markeredgecolor = strokecolor, + # markeredgewidth = d[:markerstrokewidth], + label = d[:label], + zorder = plt.n + ) + end + + if d[:markershape] != :none + if d[:marker_z] == nothing + extrakw[:c] = color_fix(pymarkercolor(d)) + else + extrakw[:c] = convert(Vector{Float64}, d[:marker_z]) + extrakw[:cmap] = pymarkercolormap(d) + end + d[:serieshandle] = ax[:scatter](x, y; + marker = getPyPlotMarker(d[:markershape]), + s = d[:markersize] .^ 2, + edgecolors = pymarkerstrokecolor(d), + linewidths = d[:markerstrokewidth], + label = d[:label], + zorder = plt.n + 0.5, + extrakw... + ) + end + end # smoothing handleSmooth(plt, ax, d, d[:smooth]) # add the colorbar legend - if plt.plotargs[:colorbar] != :none && haskey(extra_kw, :cmap) + if plt.plotargs[:colorbar] != :none && haskey(extrakw, :cmap) PyPlot.colorbar(d[:serieshandle], ax=ax) end @@ -426,7 +454,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) plt end -function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) +function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) # 3D plots have a different underlying Axes object in PyPlot lt = d[:linetype] if lt in _3dTypes && isempty(plt.o.kwargs) diff --git a/src/backends/supported.jl b/src/backends/supported.jl index e166da34..8ab87645 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -39,7 +39,7 @@ supportedArgs(::GadflyBackend) = [ :z, :tickfont, :guidefont, :legendfont, :grid, :legend, :colorbar, - :zcolor, :levels, + :marker_z, :levels, :xerror, :yerror, :ribbon, :quiver, :orientation, @@ -93,7 +93,7 @@ supportedArgs(::PyPlotBackend) = [ :z, :tickfont, :guidefont, :legendfont, :grid, :legend, :colorbar, - :zcolor, :levels, + :marker_z, :levels, :xerror, :yerror, :ribbon, :quiver, :orientation, @@ -166,7 +166,7 @@ supportedArgs(::GRBackend) = [ :xflip, :yflip, :z, - :zcolor, # only supported for scatter/scatter3d + :marker_z, # only supported for scatter/scatter3d :tickfont, :guidefont, :legendfont, @@ -497,7 +497,7 @@ supportedArgs(::PlotlyBackend) = [ :xflip, :yflip, :z, - :zcolor, + :marker_z, :tickfont, :guidefont, :legendfont, @@ -573,7 +573,7 @@ supportedArgs(::PlotlyJSBackend) = [ :xflip, :yflip, :z, - :zcolor, + :marker_z, :tickfont, :guidefont, :legendfont,