Add :log10-colorbar_scale support in GR
This commit is contained in:
parent
19b70c06ff
commit
d1d4b4fe33
@ -377,6 +377,8 @@ const _gr_attr = merge_with_base_supported([
|
|||||||
:colorbar,
|
:colorbar,
|
||||||
:colorbar_title,
|
:colorbar_title,
|
||||||
:colorbar_entry,
|
:colorbar_entry,
|
||||||
|
:colorbar_scale,
|
||||||
|
:clims,
|
||||||
:fill_z,
|
:fill_z,
|
||||||
:line_z,
|
:line_z,
|
||||||
:marker_z,
|
:marker_z,
|
||||||
|
|||||||
@ -569,6 +569,9 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, clims, viewport_plotare
|
|||||||
|
|
||||||
ztick = 0.5 * GR.tick(zmin, zmax)
|
ztick = 0.5 * GR.tick(zmin, zmax)
|
||||||
gr_set_line(1, :solid, plot_color(:black), sp)
|
gr_set_line(1, :solid, plot_color(:black), sp)
|
||||||
|
if sp[:colorbar_scale] == :log10
|
||||||
|
GR.setscale(2)
|
||||||
|
end
|
||||||
GR.axes(0, ztick, xmax, zmin, 0, 1, 0.005)
|
GR.axes(0, ztick, xmax, zmin, 0, 1, 0.005)
|
||||||
|
|
||||||
title = if isa(sp[:colorbar_title], PlotText)
|
title = if isa(sp[:colorbar_title], PlotText)
|
||||||
@ -949,6 +952,9 @@ function get_z_normalized(z, clims...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gr_clims(args...)
|
function gr_clims(args...)
|
||||||
|
if args[1][:clims] != :auto
|
||||||
|
return args[1][:clims]
|
||||||
|
end
|
||||||
lo, hi = get_clims(args...)
|
lo, hi = get_clims(args...)
|
||||||
if lo == hi
|
if lo == hi
|
||||||
if lo == 0
|
if lo == 0
|
||||||
@ -2085,15 +2091,41 @@ function gr_draw_heatmap(series, x, y, z, clims)
|
|||||||
# pdf output, and also supports alpha values.
|
# pdf output, and also supports alpha values.
|
||||||
# Note that drawimage draws uniformly spaced data correctly
|
# Note that drawimage draws uniformly spaced data correctly
|
||||||
# even on log scales, where it is visually non-uniform.
|
# even on log scales, where it is visually non-uniform.
|
||||||
|
colors = if series[:subplot][:colorbar_scale] == :identity
|
||||||
colors = plot_color.(get(fillgrad, z, clims), series[:fillalpha])
|
colors = plot_color.(get(fillgrad, z, clims), series[:fillalpha])
|
||||||
|
elseif series[:subplot][:colorbar_scale] == :log10
|
||||||
|
z_log = log10.(z)
|
||||||
|
z_normalized = get_z_normalized.(z_log, log10.(clims)...)
|
||||||
|
colors = plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:fillalpha])
|
||||||
|
end
|
||||||
|
for i in eachindex(colors)
|
||||||
|
if z[i] < (clims[1])
|
||||||
|
colors[i] = set_RGBA_alpha(0, colors[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
rgba = gr_color.(colors)
|
rgba = gr_color.(colors)
|
||||||
GR.drawimage(first(x), last(x), last(y), first(y), w, h, rgba)
|
GR.drawimage(first(x), last(x), last(y), first(y), w, h, rgba)
|
||||||
else
|
else
|
||||||
if something(series[:fillalpha], 1) < 1
|
if something(series[:fillalpha], 1) < 1
|
||||||
@warn "GR: transparency not supported in non-uniform heatmaps. Alpha values ignored."
|
@warn "GR: transparency not supported in non-uniform heatmaps. Alpha values ignored."
|
||||||
end
|
end
|
||||||
z_normalized = get_z_normalized.(z, clims...)
|
z_normalized = if series[:subplot][:colorbar_scale] == :identity
|
||||||
|
get_z_normalized.(z, clims...)
|
||||||
|
elseif series[:subplot][:colorbar_scale] == :log10
|
||||||
|
z_log = log10.(z)
|
||||||
|
z_log = map(z -> isinf(z) ? Inf : z, z_log)
|
||||||
|
z_min = minimum(z_log)
|
||||||
|
z_log = map(z -> isinf(z) ? z_min : z, z_log)
|
||||||
|
get_z_normalized.(z_log, minimum(z_log), maximum(z_log))
|
||||||
|
end
|
||||||
rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized]
|
rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized]
|
||||||
|
for i in eachindex(rgba)
|
||||||
|
if z[i] < (clims[1])
|
||||||
|
rgba[i] = 0 # White, not transparent
|
||||||
|
elseif z[i] > (clims[end])
|
||||||
|
rgba[i] = 1255
|
||||||
|
end
|
||||||
|
end
|
||||||
if !ispolar(series)
|
if !ispolar(series)
|
||||||
GR.nonuniformcellarray(x, y, w, h, rgba)
|
GR.nonuniformcellarray(x, y, w, h, rgba)
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user