allow specifying the color gradient for z values in pyplot

This commit is contained in:
Daniel Schwabeneder 2019-06-26 12:09:59 +02:00
parent e061d156bc
commit 7f8dc486bb
2 changed files with 13 additions and 6 deletions

View File

@ -467,7 +467,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax."plot"((arg[rng] for arg in xyargs)...; handle = ax."plot"((arg[rng] for arg in xyargs)...;
label = i == 1 ? series[:label] : "", label = i == 1 ? series[:label] : "",
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
color = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)), color = py_color(single_color(get_linecolor(series, clims, i)), get_linealpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)), linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)),
solid_capstyle = "round", solid_capstyle = "round",
@ -1296,22 +1296,26 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
handles = [] handles = []
for series in series_list(sp) for series in series_list(sp)
if should_add_to_legend(series) if should_add_to_legend(series)
lc = get_linecolor(series, clims)
lc = isa(lc, ColorGradient) ? lc[0.5] : lc
# add a line/marker and a label # add a line/marker and a label
push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing
pypatches."Patch"( pypatches."Patch"(
edgecolor = py_color(get_linecolor(series, clims), get_linealpha(series)), edgecolor = py_color(single_color(get_linecolor(series, clims)), get_linealpha(series)),
facecolor = py_color(get_fillcolor(series, clims), get_fillalpha(series)), facecolor = py_color(single_color(get_fillcolor(series, clims)), get_fillalpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(series[:seriestype], get_linestyle(series)) linestyle = py_linestyle(series[:seriestype], get_linestyle(series))
) )
elseif series[:seriestype] in (:path, :straightline, :scatter) elseif series[:seriestype] in (:path, :straightline, :scatter)
PyPlot.plt."Line2D"((0,1),(0,0), PyPlot.plt."Line2D"((0,1),(0,0),
color = py_color(get_linecolor(series, clims), get_linealpha(series)), color = py_color(single_color(get_linecolor(series, clims)), get_linealpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(:path, get_linestyle(series)), linestyle = py_linestyle(:path, get_linestyle(series)),
marker = py_marker(first(series[:markershape])), marker = py_marker(first(series[:markershape])),
markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), markeredgecolor = py_color(single_color(get_markerstrokecolor(series)), get_markerstrokealpha(series)),
markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series, clims), get_markeralpha(series)) : py_color(series[:markercolor][0.5]) markerfacecolor = py_color(single_color(get_markercolor(series, clims)), get_markeralpha(series))
) )
else else
series[:serieshandle][1] series[:serieshandle][1]

View File

@ -625,6 +625,9 @@ for comp in (:line, :fill, :marker)
end end
end end
single_color(c, v = 0.5) = c
single_color(grad::ColorGradient, v = 0.5) = grad[v]
function get_linewidth(series, i::Int = 1) function get_linewidth(series, i::Int = 1)
_cycle(series[:linewidth], i) _cycle(series[:linewidth], i)
end end