working on seriescolor and pyplot reorgs

This commit is contained in:
Thomas Breloff 2016-04-22 10:44:12 -04:00
parent e2ae22421b
commit b9818a4480
3 changed files with 137 additions and 83 deletions

View File

@ -252,6 +252,7 @@ end
:width => :linewidth, :width => :linewidth,
:lw => :linewidth, :lw => :linewidth,
:la => :linealpha, :la => :linealpha,
:lalpha => :linealpha,
:lineopacity => :linealpha, :lineopacity => :linealpha,
:type => :linetype, :type => :linetype,
:lt => :linetype, :lt => :linetype,
@ -280,6 +281,7 @@ end
:fcolor => :fillcolor, :fcolor => :fillcolor,
:fillcolour => :fillcolor, :fillcolour => :fillcolor,
:fa => :fillalpha, :fa => :fillalpha,
:falpha => :fillalpha,
:fillopacity => :fillalpha, :fillopacity => :fillalpha,
:g => :group, :g => :group,
:nb => :nbins, :nb => :nbins,
@ -794,25 +796,49 @@ function getSeriesArgs(pkg::AbstractBackend, plotargs::KW, kw, commandIndex::Int
# update color # update color
d[:seriescolor] = getSeriesRGBColor(d[:seriescolor], plotargs, plotIndex) d[:seriescolor] = getSeriesRGBColor(d[:seriescolor], plotargs, plotIndex)
# update linecolor # # update linecolor
c = d[:linecolor] # c = d[:linecolor]
c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) # c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex))
d[:linecolor] = c # d[:linecolor] = c
# update markercolor # # update markercolor
c = d[:markercolor] # c = d[:markercolor]
c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) # c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex))
d[:markercolor] = c # 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 # update markerstrokecolor
c = d[:markerstrokecolor] c = d[:markerstrokecolor]
c = (c == :match ? plotargs[:foreground_color] : getSeriesRGBColor(c, plotargs, plotIndex)) c = (c == :match ? plotargs[:foreground_color] : getSeriesRGBColor(c, plotargs, plotIndex))
d[:markerstrokecolor] = c d[:markerstrokecolor] = c
# update fillcolor # update alphas
c = d[:fillcolor] for asym in (:linealpha, :markeralpha, :fillalpha)
c = (c == :match ? d[:seriescolor] : getSeriesRGBColor(c, plotargs, plotIndex)) if d[asym] == nothing
d[:fillcolor] = c 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 # set label
label = d[:label] label = d[:label]

View File

@ -294,37 +294,53 @@ function fix_xy_lengths!(plt::Plot{PyPlotBackend}, d::KW)
end end
end end
# figure out the extra kw from zcolor in scatter and scatter3d # # figure out the extra kw from zcolor in scatter and scatter3d
function get_extra_kw(plt::Plot{PyPlotBackend}, d::KW) # function get_extra_kw(plt::Plot{PyPlotBackend}, d::KW)
extra_kw = KW() # extra_kw = KW()
if d[:linetype] in (:scatter, :scatter3d) # if d[:linetype] in (:scatter, :scatter3d)
c = getPyPlotColor(d[:markercolor]) # c = getPyPlotColor(d[:markercolor])
if d[:marker_z] == nothing # if d[:marker_z] == nothing
c = getPyPlotColor(c, d[:markeralpha]) # 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). # 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 # 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) function color_fix(c)
c = vcat(c, c) if (typeof(c) <: AbstractArray && length(c)*4 == length(x)) ||
end (typeof(c) <: Tuple && length(x) == 4)
extra_kw[:c] = c vcat(c, c)
else else
if !isa(c, ColorGradient) c
c = default_gradient()
end
extra_kw[:c] = convert(Vector{Float64}, d[:marker_z])
extra_kw[:cmap] = getPyPlotColorMap(c, d[:markeralpha])
end
end end
extra_kw
end 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_series(pkg::PyPlotBackend, plt::Plot, d::KW)
function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW)
lt = d[:linetype] lt = d[:linetype]
if !(lt in supportedTypes(pkg)) if !(lt in supportedTypes(pkg))
error("linetype $(lt) is unsupported in PyPlot. Choose from: $(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) fix_xy_lengths!(plt, d)
ax = getAxis(plt, d[:axis]) ax = getAxis(plt, d[:axis])
linecolor = getPyPlotColor(d[:linecolor], d[:linealpha]) # linecolor = getPyPlotColor(d[:linecolor], d[:linealpha])
markercolor = if d[:marker_z] == nothing # markercolor = if d[:marker_z] == nothing
getPyPlotColor(d[:markercolor], d[:markeralpha]) # getPyPlotColor(d[:markercolor], d[:markeralpha])
else # else
getPyPlotColorMap(d[:markercolor], d[:markeralpha]) # getPyPlotColorMap(d[:markercolor], d[:markeralpha])
end # end
fillcolor = getPyPlotColor(d[:fillcolor], d[:fillalpha]) # fillcolor = getPyPlotColor(d[:fillcolor], d[:fillalpha])
strokecolor = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha]) # strokecolor = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha])
# linecmap = getPyPlotColorMap(d[:linecolor], d[:linealpha]) # linecmap = getPyPlotColorMap(d[:linecolor], d[:linealpha])
# fillcmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]) # fillcmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])
linestyle = getPyPlotLineStyle(lt, d[:linestyle]) # linestyle = getPyPlotLineStyle(lt, d[:linestyle])
markershape = getPyPlotMarker(d[:markershape]) # markershape = getPyPlotMarker(d[:markershape])
x, y, z = d[:x], d[:y], d[:z] 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 # handle zcolor and get c/cmap
extra_kw = get_extra_kw(plt, d) # extra_kw = get_extra_kw(plt, d)
extrakw = KW()
# :hist => :hist, # :hist => :hist,
# :density => :hist, # :density => :hist,
@ -373,39 +392,48 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW)
# :shape => :add_patch, # :shape => :add_patch,
# #
# do the plotting # do the plotting
if lt in (:path, :line) if lt in (:path, :line, :scatter)
ax[:plot](x, y; if d[:linewidth] > 0
color = linecolor, d[:serieshandle] = ax[:plot](x, y;
linewidth = linewidth, color = pylinecolor(d),
linestyle = linestyle, linewidth = d[:linewidth],
drawstyle = getPyPlotStepStyle(lt), linestyle = getPyPlotLineStyle(lt, d[:linestyle]),
marker = markershape, drawstyle = getPyPlotStepStyle(lt),
markersize = d[:markersize], # marker = markershape,
markerfacecolor = markercolor, # markersize = d[:markersize],
markeredgecolor = strokecolor, # markerfacecolor = markercolor,
markeredgewidth = d[:markerstrokewidth], # markeredgecolor = strokecolor,
label = d[:label], # markeredgewidth = d[:markerstrokewidth],
zorder = plt.n label = d[:label],
) zorder = plt.n
elseif lt == :scatter )
ax[:plot](x, y; end
linewidth = 0,
marker = markershape, if d[:markershape] != :none
markersize = d[:markersize], if d[:marker_z] == nothing
markerfacecolor = markercolor, extrakw[:c] = color_fix(pymarkercolor(d))
markeredgecolor = strokecolor, else
markeredgewidth = d[:markerstrokewidth], extrakw[:c] = convert(Vector{Float64}, d[:marker_z])
label = d[:label], extrakw[:cmap] = pymarkercolormap(d)
zorder = plt.n, end
extra_kw... 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 end
# smoothing # smoothing
handleSmooth(plt, ax, d, d[:smooth]) handleSmooth(plt, ax, d, d[:smooth])
# add the colorbar legend # 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) PyPlot.colorbar(d[:serieshandle], ax=ax)
end end
@ -426,7 +454,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW)
plt plt
end 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 # 3D plots have a different underlying Axes object in PyPlot
lt = d[:linetype] lt = d[:linetype]
if lt in _3dTypes && isempty(plt.o.kwargs) if lt in _3dTypes && isempty(plt.o.kwargs)

View File

@ -39,7 +39,7 @@ supportedArgs(::GadflyBackend) = [
:z, :z,
:tickfont, :guidefont, :legendfont, :tickfont, :guidefont, :legendfont,
:grid, :legend, :colorbar, :grid, :legend, :colorbar,
:zcolor, :levels, :marker_z, :levels,
:xerror, :yerror, :xerror, :yerror,
:ribbon, :quiver, :ribbon, :quiver,
:orientation, :orientation,
@ -93,7 +93,7 @@ supportedArgs(::PyPlotBackend) = [
:z, :z,
:tickfont, :guidefont, :legendfont, :tickfont, :guidefont, :legendfont,
:grid, :legend, :colorbar, :grid, :legend, :colorbar,
:zcolor, :levels, :marker_z, :levels,
:xerror, :yerror, :xerror, :yerror,
:ribbon, :quiver, :ribbon, :quiver,
:orientation, :orientation,
@ -166,7 +166,7 @@ supportedArgs(::GRBackend) = [
:xflip, :xflip,
:yflip, :yflip,
:z, :z,
:zcolor, # only supported for scatter/scatter3d :marker_z, # only supported for scatter/scatter3d
:tickfont, :tickfont,
:guidefont, :guidefont,
:legendfont, :legendfont,
@ -497,7 +497,7 @@ supportedArgs(::PlotlyBackend) = [
:xflip, :xflip,
:yflip, :yflip,
:z, :z,
:zcolor, :marker_z,
:tickfont, :tickfont,
:guidefont, :guidefont,
:legendfont, :legendfont,
@ -573,7 +573,7 @@ supportedArgs(::PlotlyJSBackend) = [
:xflip, :xflip,
:yflip, :yflip,
:z, :z,
:zcolor, :marker_z,
:tickfont, :tickfont,
:guidefont, :guidefont,
:legendfont, :legendfont,