From 7f8dc486bb185937866684fb5d64f280e20db24b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 26 Jun 2019 12:09:59 +0200 Subject: [PATCH 1/2] allow specifying the color gradient for z values in pyplot --- src/backends/pyplot.jl | 16 ++++++++++------ src/utils.jl | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5b4939ed..e5424a01 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -467,7 +467,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) handle = ax."plot"((arg[rng] for arg in xyargs)...; label = i == 1 ? series[:label] : "", 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)), linestyle = py_linestyle(st, get_linestyle(series, i)), solid_capstyle = "round", @@ -1296,22 +1296,26 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) handles = [] for series in series_list(sp) 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 push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing pypatches."Patch"( - edgecolor = py_color(get_linecolor(series, clims), get_linealpha(series)), - facecolor = py_color(get_fillcolor(series, clims), get_fillalpha(series)), + edgecolor = py_color(single_color(get_linecolor(series, clims)), get_linealpha(series)), + facecolor = py_color(single_color(get_fillcolor(series, clims)), get_fillalpha(series)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linestyle = py_linestyle(series[:seriestype], get_linestyle(series)) ) elseif series[:seriestype] in (:path, :straightline, :scatter) 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)), linestyle = py_linestyle(:path, get_linestyle(series)), marker = py_marker(first(series[:markershape])), - markeredgecolor = py_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]) + markeredgecolor = py_color(single_color(get_markerstrokecolor(series)), get_markerstrokealpha(series)), + markerfacecolor = py_color(single_color(get_markercolor(series, clims)), get_markeralpha(series)) ) else series[:serieshandle][1] diff --git a/src/utils.jl b/src/utils.jl index 8f1873d3..f86c7768 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -625,6 +625,9 @@ for comp in (:line, :fill, :marker) 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) _cycle(series[:linewidth], i) end From 2f14c37c598cba677a2c67cd9f16370345b01f1b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 26 Jun 2019 13:04:14 +0200 Subject: [PATCH 2/2] remove unnecessary lines --- src/backends/pyplot.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index e5424a01..eec1e6ca 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1296,10 +1296,6 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) handles = [] for series in series_list(sp) 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 push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing pypatches."Patch"(