pyplot log scale colorbar support

This commit is contained in:
zhanibek 2021-07-06 15:46:10 +09:00
parent 3c639bd35e
commit d4140912a8
2 changed files with 17 additions and 10 deletions

View File

@ -510,7 +510,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = series[:series_plotindex] + 0.5,
marker = py_marker(_cycle(series[:markershape], i)),
s = py_thickness_scale(plt, _cycle(series[:markersize], i)).^ 2,
facecolors = py_color(get_markercolor(series, i), get_markeralpha(series, i)),
facecolors = py_color(get_markercolor(series, clims, i, sp[:colorbar_scale]), get_markeralpha(series, i)),
edgecolors = py_color(get_markerstrokecolor(series, i), get_markerstrokealpha(series, i)),
linewidths = py_thickness_scale(plt, get_markerstrokewidth(series, i)),
extrakw...
@ -691,8 +691,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
path;
label = series[:label],
zorder = series[:series_plotindex],
edgecolor = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
edgecolor = py_color(get_linecolor(series, clims, i, sp[:colorbar_scale]), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, clims, i, sp[:colorbar_scale]), get_fillalpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)),
fill = true
@ -727,7 +727,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = getproperty(ax, f)(args..., trues(n), false, py_fillstepstyle(st);
zorder = series[:series_plotindex],
facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
facecolor = py_color(get_fillcolor(series, clims, i, sp[:colorbar_scale]), get_fillalpha(series, i)),
linewidths = 0
)
push!(handles, handle)
@ -1386,8 +1386,8 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
push!(handles,
if series[:seriestype] == :shape || series[:fillrange] !== nothing
pypatches."Patch"(
edgecolor = py_color(single_color(get_linecolor(series, clims)), get_linealpha(series)),
facecolor = py_color(single_color(get_fillcolor(series, clims)), get_fillalpha(series)),
edgecolor = py_color(single_color(get_linecolor(series, clims, sp[:colorbar_scale])), get_linealpha(series)),
facecolor = py_color(single_color(get_fillcolor(series, clims, sp[:colorbar_scale])), get_fillalpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(series[:seriestype], get_linestyle(series)),
capstyle = "butt"
@ -1395,7 +1395,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
elseif series[:seriestype] in (:path, :straightline, :scatter, :steppre, :stepmid, :steppost)
hasline = get_linewidth(series) > 0
PyPlot.plt."Line2D"((0, 1),(0,0),
color = py_color(single_color(get_linecolor(series, clims)), get_linealpha(series)),
color = py_color(single_color(get_linecolor(series, clims, sp[:colorbar_scale])), get_linealpha(series)),
linewidth = py_thickness_scale(plt, hasline * sp[:legendfontsize] / 8),
linestyle = py_linestyle(:path, get_linestyle(series)),
solid_capstyle = "butt", solid_joinstyle = "miter",
@ -1403,7 +1403,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
marker = py_marker(_cycle(series[:markershape], 1)),
markersize = py_thickness_scale(plt, 0.8 * sp[:legendfontsize]),
markeredgecolor = py_color(single_color(get_markerstrokecolor(series)), get_markerstrokealpha(series)),
markerfacecolor = py_color(single_color(get_markercolor(series, clims)), get_markeralpha(series)),
markerfacecolor = py_color(single_color(get_markercolor(series, clims, sp[:colorbar_scale])), get_markeralpha(series)),
markeredgewidth = py_thickness_scale(plt, 0.8 * get_markerstrokewidth(series) * sp[:legendfontsize] / first(series[:markersize])) # retain the markersize/markerstroke ratio from the markers on the plot
)
else

View File

@ -476,17 +476,24 @@ for comp in (:line, :fill, :marker)
@eval begin
function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1)
function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1, scale::Symbol = :identity)
c = series[$Symbol($compcolor)]
z = series[$Symbol($comp_z)]
if z === nothing
isa(c, ColorGradient) ? c : plot_color(_cycle(c, i))
else
get(get_gradient(c), z[i], (cmin, cmax))
if scale === :identity
return get(get_gradient(c), z[i], (cmin, cmax))
elseif scale == :log10
return get(get_gradient(c), log10(z[i]), (log10(cmin), log10(cmax)))
else
@warn("Undefined colorbar scale")
end
end
end
$get_compcolor(series, clims, i::Int = 1) = $get_compcolor(series, clims[1], clims[2], i)
$get_compcolor(series, clims, i::Int = 1, scale=:identity) = $get_compcolor(series, clims[1], clims[2], i, scale)
function $get_compcolor(series, i::Int = 1)
if series[$Symbol($comp_z)] === nothing