Merge pull request #1969 from yha/contour-colorbar
Some more fixes for contours and colorbars (mostly GR)
This commit is contained in:
commit
16db531cce
29
src/args.jl
29
src/args.jl
@ -232,6 +232,7 @@ const _bar_width = 0.8
|
|||||||
|
|
||||||
const _series_defaults = KW(
|
const _series_defaults = KW(
|
||||||
:label => "AUTO",
|
:label => "AUTO",
|
||||||
|
:colorbar_entry => true,
|
||||||
:seriescolor => :auto,
|
:seriescolor => :auto,
|
||||||
:seriesalpha => nothing,
|
:seriesalpha => nothing,
|
||||||
:seriestype => :path,
|
:seriestype => :path,
|
||||||
@ -1509,19 +1510,19 @@ function has_black_border_for_default(st::Symbol)
|
|||||||
like_histogram(st) || st in (:hexbin, :bar, :shape)
|
like_histogram(st) || st in (:hexbin, :bar, :shape)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# converts a symbol or string into a Colorant or ColorGradient
|
||||||
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
# and assigns a color automatically
|
||||||
function getSeriesRGBColor(c, sp::Subplot, n::Int)
|
function get_series_color(c, sp::Subplot, n::Int, seriestype)
|
||||||
if c == :auto
|
if c == :auto
|
||||||
c = autopick(sp[:color_palette], n)
|
c = like_surface(seriestype) ? cgrad() : autopick(sp[:color_palette], n)
|
||||||
elseif isa(c, Int)
|
elseif isa(c, Int)
|
||||||
c = autopick(sp[:color_palette], c)
|
c = autopick(sp[:color_palette], c)
|
||||||
end
|
end
|
||||||
plot_color(c)
|
plot_color(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
function getSeriesRGBColor(c::AbstractArray, sp::Subplot, n::Int)
|
function get_series_color(c::AbstractArray, sp::Subplot, n::Int, seriestype)
|
||||||
map(x->getSeriesRGBColor(x, sp, n), c)
|
map(x->get_series_color(x, sp, n), c, seriestype)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ensure_gradient!(plotattributes::KW, csym::Symbol, asym::Symbol)
|
function ensure_gradient!(plotattributes::KW, csym::Symbol, asym::Symbol)
|
||||||
@ -1566,21 +1567,23 @@ function _update_series_attributes!(plotattributes::KW, plt::Plot, sp::Subplot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# update series color
|
# update series color
|
||||||
plotattributes[:seriescolor] = getSeriesRGBColor(plotattributes[:seriescolor], sp, plotIndex)
|
scolor = plotattributes[:seriescolor]
|
||||||
|
stype = plotattributes[:seriestype]
|
||||||
|
plotattributes[:seriescolor] = scolor = get_series_color(scolor, sp, plotIndex, stype)
|
||||||
|
|
||||||
# update other colors
|
# update other colors
|
||||||
for s in (:line, :marker, :fill)
|
for s in (:line, :marker, :fill)
|
||||||
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
||||||
plotattributes[csym] = if plotattributes[csym] == :auto
|
plotattributes[csym] = if plotattributes[csym] == :auto
|
||||||
plot_color(if has_black_border_for_default(plotattributes[:seriestype]) && s == :line
|
plot_color(if has_black_border_for_default(stype) && s == :line
|
||||||
sp[:foreground_color_subplot]
|
sp[:foreground_color_subplot]
|
||||||
else
|
else
|
||||||
plotattributes[:seriescolor]
|
scolor
|
||||||
end)
|
end)
|
||||||
elseif plotattributes[csym] == :match
|
elseif plotattributes[csym] == :match
|
||||||
plot_color(plotattributes[:seriescolor])
|
plot_color(scolor)
|
||||||
else
|
else
|
||||||
getSeriesRGBColor(plotattributes[csym], sp, plotIndex)
|
get_series_color(plotattributes[csym], sp, plotIndex, stype)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1588,9 +1591,9 @@ function _update_series_attributes!(plotattributes::KW, plt::Plot, sp::Subplot)
|
|||||||
plotattributes[:markerstrokecolor] = if plotattributes[:markerstrokecolor] == :match
|
plotattributes[:markerstrokecolor] = if plotattributes[:markerstrokecolor] == :match
|
||||||
plot_color(sp[:foreground_color_subplot])
|
plot_color(sp[:foreground_color_subplot])
|
||||||
elseif plotattributes[:markerstrokecolor] == :auto
|
elseif plotattributes[:markerstrokecolor] == :auto
|
||||||
getSeriesRGBColor(plotattributes[:markercolor], sp, plotIndex)
|
get_series_color(plotattributes[:markercolor], sp, plotIndex, stype)
|
||||||
else
|
else
|
||||||
getSeriesRGBColor(plotattributes[:markerstrokecolor], sp, plotIndex)
|
get_series_color(plotattributes[:markerstrokecolor], sp, plotIndex, stype)
|
||||||
end
|
end
|
||||||
|
|
||||||
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
||||||
|
|||||||
@ -332,7 +332,7 @@ const _gr_attr = merge_with_base_supported([
|
|||||||
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
|
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
|
||||||
:guidefontrotation, :guidefontcolor,
|
:guidefontrotation, :guidefontcolor,
|
||||||
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
||||||
:legend, :legendtitle, :colorbar, :colorbar_title,
|
:legend, :legendtitle, :colorbar, :colorbar_title, :colorbar_entry,
|
||||||
:fill_z, :line_z, :marker_z, :levels,
|
:fill_z, :line_z, :marker_z, :levels,
|
||||||
:ribbon, :quiver,
|
:ribbon, :quiver,
|
||||||
:orientation,
|
:orientation,
|
||||||
@ -386,7 +386,7 @@ const _plotly_attr = merge_with_base_supported([
|
|||||||
:guide, :lims, :ticks, :scale, :flip, :rotation,
|
:guide, :lims, :ticks, :scale, :flip, :rotation,
|
||||||
:tickfont, :guidefont, :legendfont,
|
:tickfont, :guidefont, :legendfont,
|
||||||
:grid, :gridalpha, :gridlinewidth,
|
:grid, :gridalpha, :gridlinewidth,
|
||||||
:legend, :colorbar, :colorbar_title,
|
:legend, :colorbar, :colorbar_title, :colorbar_entry,
|
||||||
:marker_z, :fill_z, :line_z, :levels,
|
:marker_z, :fill_z, :line_z, :levels,
|
||||||
:ribbon, :quiver,
|
:ribbon, :quiver,
|
||||||
:orientation,
|
:orientation,
|
||||||
@ -511,7 +511,7 @@ const _pyplot_attr = merge_with_base_supported([
|
|||||||
:tickfontfamily, :tickfontsize, :tickfontcolor,
|
:tickfontfamily, :tickfontsize, :tickfontcolor,
|
||||||
:guidefontfamily, :guidefontsize, :guidefontcolor,
|
:guidefontfamily, :guidefontsize, :guidefontcolor,
|
||||||
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
||||||
:legend, :legendtitle, :colorbar,
|
:legend, :legendtitle, :colorbar, :colorbar_title, :colorbar_entry,
|
||||||
:marker_z, :line_z, :fill_z,
|
:marker_z, :line_z, :fill_z,
|
||||||
:levels,
|
:levels,
|
||||||
:ribbon, :quiver, :arrow,
|
:ribbon, :quiver, :arrow,
|
||||||
@ -524,7 +524,6 @@ const _pyplot_attr = merge_with_base_supported([
|
|||||||
:clims,
|
:clims,
|
||||||
:inset_subplots,
|
:inset_subplots,
|
||||||
:dpi,
|
:dpi,
|
||||||
:colorbar_title,
|
|
||||||
:stride,
|
:stride,
|
||||||
:framestyle,
|
:framestyle,
|
||||||
:tick_direction,
|
:tick_direction,
|
||||||
|
|||||||
@ -415,24 +415,96 @@ function gr_set_viewport_polar()
|
|||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
struct GRColorbar
|
||||||
|
gradient::Ref{Union{Series,Nothing}}
|
||||||
|
fill::Ref{Union{Series,Nothing}}
|
||||||
|
lines::Ref{Union{Series,Nothing}}
|
||||||
|
GRColorbar() = new(nothing,nothing,nothing)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gr_update_colorbar!(cbar::GRColorbar, series::Series)
|
||||||
|
style = colorbar_style(series)
|
||||||
|
style === nothing && return
|
||||||
|
ref = style == cbar_gradient ? cbar.gradient :
|
||||||
|
style == cbar_fill ? cbar.fill :
|
||||||
|
style == cbar_lines ? cbar.lines :
|
||||||
|
error("Unknown colorbar style: $style.")
|
||||||
|
if ref[] !== nothing
|
||||||
|
@warn "Overwriting colorbar entry"
|
||||||
|
end
|
||||||
|
ref[] = series
|
||||||
|
end
|
||||||
|
|
||||||
|
function gr_contour_levels(series::Series, clims)
|
||||||
|
levels = contour_levels(series, clims)
|
||||||
|
if isfilledcontour(series)
|
||||||
|
# GR implicitly uses the maximal z value as the highest level
|
||||||
|
levels = levels[1:end-1]
|
||||||
|
end
|
||||||
|
levels
|
||||||
|
end
|
||||||
|
|
||||||
|
function gr_colorbar_colors(series::Series, clims)
|
||||||
|
if iscontour(series)
|
||||||
|
levels = gr_contour_levels(series, clims)
|
||||||
|
if isfilledcontour(series)
|
||||||
|
# GR.contourf uses a color range according to supplied levels
|
||||||
|
zrange = ignorenan_extrema(levels)
|
||||||
|
else
|
||||||
|
# GR.contour uses a color range according to data range
|
||||||
|
zrange = clims
|
||||||
|
end
|
||||||
|
colors = 1000 .+ 255 .* (levels .- zrange[1]) ./ (zrange[2] - zrange[1])
|
||||||
|
else
|
||||||
|
colors = 1000:1255
|
||||||
|
end
|
||||||
|
round.(Int,colors)
|
||||||
|
end
|
||||||
|
|
||||||
# add the colorbar
|
# add the colorbar
|
||||||
function gr_colorbar(sp::Subplot, clims, levels)
|
function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, clims)
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
xmin, xmax = gr_xy_axislims(sp)[1:2]
|
xmin, xmax = gr_xy_axislims(sp)[1:2]
|
||||||
zmin, zmax = clims[1:2]
|
zmin, zmax = clims[1:2]
|
||||||
gr_set_viewport_cmap(sp)
|
gr_set_viewport_cmap(sp)
|
||||||
l = if levels === nothing
|
|
||||||
(1000:1255)'
|
|
||||||
elseif length(levels) > 1
|
|
||||||
min_level, max_level = ignorenan_minimum(levels), ignorenan_maximum(levels)
|
|
||||||
round.(Int32, 1000 .+ (levels .- min_level) ./ (max_level - min_level) .* 255)
|
|
||||||
else
|
|
||||||
Int32[1000, 1255]
|
|
||||||
end
|
|
||||||
GR.setscale(0)
|
GR.setscale(0)
|
||||||
GR.setwindow(xmin, xmax, zmin, zmax)
|
GR.setwindow(xmin, xmax, zmin, zmax)
|
||||||
GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l)
|
if (series = cbar.gradient[]) !== nothing
|
||||||
|
gr_set_gradient(series)
|
||||||
|
GR.cellarray(xmin, xmax, zmax, zmin, 1, 256, 1000:1255)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (series = cbar.fill[]) !== nothing
|
||||||
|
gr_set_gradient(series)
|
||||||
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
|
levels = contour_levels(series, clims)
|
||||||
|
# GR implicitly uses the maximal z value as the highest level
|
||||||
|
if levels[end] < clims[2]
|
||||||
|
@warn("GR: highest contour level less than maximal z value is not supported.")
|
||||||
|
# replace levels, rather than assign to levels[end], to ensure type
|
||||||
|
# promotion in case levels is an integer array
|
||||||
|
levels = [levels[1:end-1]; clims[2]]
|
||||||
|
end
|
||||||
|
colors = gr_colorbar_colors(series, clims)
|
||||||
|
for (from, to, color) in zip(levels[1:end-1], levels[2:end], colors)
|
||||||
|
GR.setfillcolorind(color)
|
||||||
|
GR.fillrect( xmin, xmax, from, to )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (series = cbar.lines[]) !== nothing
|
||||||
|
gr_set_gradient(series)
|
||||||
|
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series, clims))
|
||||||
|
levels = contour_levels(series, clims)
|
||||||
|
colors = gr_colorbar_colors(series, clims)
|
||||||
|
for (line, color) in zip(levels, colors)
|
||||||
|
GR.setlinecolorind(color)
|
||||||
|
GR.polyline([xmin,xmax], [line,line] )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
ztick = 0.5 * GR.tick(zmin, zmax)
|
ztick = 0.5 * GR.tick(zmin, zmax)
|
||||||
|
gr_set_line(1, :solid, plot_color(:black))
|
||||||
GR.axes(0, ztick, xmax, zmin, 0, 1, 0.005)
|
GR.axes(0, ztick, xmax, zmin, 0, 1, 0.005)
|
||||||
|
|
||||||
gr_set_font(guidefont(sp[:yaxis]))
|
gr_set_font(guidefont(sp[:yaxis]))
|
||||||
@ -480,7 +552,7 @@ end
|
|||||||
const _gr_gradient_alpha = ones(256)
|
const _gr_gradient_alpha = ones(256)
|
||||||
|
|
||||||
function gr_set_gradient(c)
|
function gr_set_gradient(c)
|
||||||
grad = c isa ColorGradient ? c : cgrad()
|
grad = _as_gradient(c)
|
||||||
for (i,z) in enumerate(range(0, stop=1, length=256))
|
for (i,z) in enumerate(range(0, stop=1, length=256))
|
||||||
c = grad[z]
|
c = grad[z]
|
||||||
GR.setcolorrep(999+i, red(c), green(c), blue(c))
|
GR.setcolorrep(999+i, red(c), green(c), blue(c))
|
||||||
@ -489,6 +561,21 @@ function gr_set_gradient(c)
|
|||||||
grad
|
grad
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function gr_set_gradient(series::Series)
|
||||||
|
st = series[:seriestype]
|
||||||
|
if st in (:surface, :heatmap) || isfilledcontour(series)
|
||||||
|
gr_set_gradient(series[:fillcolor])
|
||||||
|
elseif st in (:contour, :wireframe)
|
||||||
|
gr_set_gradient(series[:linecolor])
|
||||||
|
elseif series[:marker_z] != nothing
|
||||||
|
gr_set_gradient(series[:markercolor])
|
||||||
|
elseif series[:line_z] != nothing
|
||||||
|
gr_set_gradient(series[:linecolor])
|
||||||
|
elseif series[:fill_z] != nothing
|
||||||
|
gr_set_gradient(series[:fillcolor])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
|
# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
|
||||||
function gr_display(plt::Plot, fmt="")
|
function gr_display(plt::Plot, fmt="")
|
||||||
GR.clearws()
|
GR.clearws()
|
||||||
@ -671,7 +758,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
outside_ticks = false
|
outside_ticks = false
|
||||||
# calculate the colorbar limits once for a subplot
|
# calculate the colorbar limits once for a subplot
|
||||||
clims = get_clims(sp)
|
clims = get_clims(sp)
|
||||||
clevels = nothing
|
cbar = GRColorbar()
|
||||||
|
|
||||||
draw_axes = sp[:framestyle] != :none
|
draw_axes = sp[:framestyle] != :none
|
||||||
# axes_2d = true
|
# axes_2d = true
|
||||||
@ -695,8 +782,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
data_lims = gr_xy_axislims(sp)
|
data_lims = gr_xy_axislims(sp)
|
||||||
end
|
end
|
||||||
|
|
||||||
# color levels overwritten by the last relevant series
|
gr_update_colorbar!(cbar,series)
|
||||||
hascolorbar(series) && (clevels = colorbar_levels(series, clims))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# set our plot area view
|
# set our plot area view
|
||||||
@ -970,24 +1056,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
for (idx, series) in enumerate(series_list(sp))
|
for (idx, series) in enumerate(series_list(sp))
|
||||||
st = series[:seriestype]
|
st = series[:seriestype]
|
||||||
|
|
||||||
# update the current stored gradient
|
# update the current stored gradient
|
||||||
if st in (:surface, :heatmap) ||
|
gr_set_gradient(series)
|
||||||
(st == :contour && series[:fillrange] !== nothing)
|
|
||||||
gr_set_gradient(series[:fillcolor]) #, series[:fillalpha])
|
|
||||||
elseif st in (:contour, :wireframe)
|
|
||||||
gr_set_gradient(series[:linecolor])
|
|
||||||
elseif series[:marker_z] != nothing
|
|
||||||
series[:markercolor] = gr_set_gradient(series[:markercolor])
|
|
||||||
elseif series[:line_z] != nothing
|
|
||||||
series[:linecolor] = gr_set_gradient(series[:linecolor])
|
|
||||||
elseif series[:fill_z] != nothing
|
|
||||||
series[:fillcolor] = gr_set_gradient(series[:fillcolor])
|
|
||||||
end
|
|
||||||
|
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
|
|
||||||
|
|
||||||
# update the bounding window
|
# update the bounding window
|
||||||
if ispolar(sp)
|
if ispolar(sp)
|
||||||
gr_set_viewport_polar()
|
gr_set_viewport_polar()
|
||||||
@ -1053,12 +1127,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
elseif st == :contour
|
elseif st == :contour
|
||||||
GR.setspace(clims[1], clims[2], 0, 90)
|
GR.setspace(clims[1], clims[2], 0, 90)
|
||||||
h = colorbar_levels(series, clims)
|
|
||||||
GR.setlinetype(gr_linetype[get_linestyle(series)])
|
GR.setlinetype(gr_linetype[get_linestyle(series)])
|
||||||
GR.setlinewidth(max(0, get_linewidth(series) / (sum(gr_plot_size) * 0.001)))
|
GR.setlinewidth(max(0, get_linewidth(series) / (sum(gr_plot_size) * 0.001)))
|
||||||
is_lc_black = let black=plot_color(:black)
|
is_lc_black = let black=plot_color(:black)
|
||||||
plot_color(series[:linecolor]) in (black,[black])
|
plot_color(series[:linecolor]) in (black,[black])
|
||||||
end
|
end
|
||||||
|
h = gr_contour_levels(series, clims)
|
||||||
if series[:fillrange] != nothing
|
if series[:fillrange] != nothing
|
||||||
if series[:fillcolor] != series[:linecolor] && !is_lc_black
|
if series[:fillcolor] != series[:linecolor] && !is_lc_black
|
||||||
@warn("GR: filled contour only supported with black contour lines")
|
@warn("GR: filled contour only supported with black contour lines")
|
||||||
@ -1228,7 +1302,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# draw the colorbar
|
# draw the colorbar
|
||||||
hascolorbar(sp) && gr_colorbar(sp, clims, clevels)
|
hascolorbar(sp) && gr_draw_colorbar(cbar, sp, clims)
|
||||||
|
|
||||||
# add the legend
|
# add the legend
|
||||||
if sp[:legend] != :none
|
if sp[:legend] != :none
|
||||||
|
|||||||
@ -354,7 +354,7 @@ end
|
|||||||
function plotly_colorscale(grad::ColorGradient, α)
|
function plotly_colorscale(grad::ColorGradient, α)
|
||||||
[[grad.values[i], rgba_string(plot_color(grad.colors[i], α))] for i in 1:length(grad.colors)]
|
[[grad.values[i], rgba_string(plot_color(grad.colors[i], α))] for i in 1:length(grad.colors)]
|
||||||
end
|
end
|
||||||
plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α)
|
plotly_colorscale(c::Colorant,α) = plotly_colorscale(_as_gradient(c),α)
|
||||||
function plotly_colorscale(c::AbstractVector{<:RGBA}, α)
|
function plotly_colorscale(c::AbstractVector{<:RGBA}, α)
|
||||||
if length(c) == 1
|
if length(c) == 1
|
||||||
return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]]
|
return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]]
|
||||||
@ -506,13 +506,13 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
plotattributes_out[:showscale] = hascolorbar(sp)
|
plotattributes_out[:showscale] = hascolorbar(sp)
|
||||||
|
|
||||||
elseif st == :contour
|
elseif st == :contour
|
||||||
|
filled = isfilledcontour(series)
|
||||||
plotattributes_out[:type] = "contour"
|
plotattributes_out[:type] = "contour"
|
||||||
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z
|
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z
|
||||||
# plotattributes_out[:showscale] = series[:colorbar] != :none
|
plotattributes_out[:ncontours] = series[:levels] + 2
|
||||||
plotattributes_out[:ncontours] = series[:levels]
|
plotattributes_out[:contours] = KW(:coloring => filled ? "fill" : "lines", :showlabels => series[:contour_labels] == true)
|
||||||
plotattributes_out[:contours] = KW(:coloring => series[:fillrange] != nothing ? "fill" : "lines", :showlabels => series[:contour_labels] == true)
|
|
||||||
plotattributes_out[:colorscale] = plotly_colorscale(series[:linecolor], series[:linealpha])
|
plotattributes_out[:colorscale] = plotly_colorscale(series[:linecolor], series[:linealpha])
|
||||||
plotattributes_out[:showscale] = hascolorbar(sp)
|
plotattributes_out[:showscale] = hascolorbar(sp) && hascolorbar(series)
|
||||||
|
|
||||||
elseif st in (:surface, :wireframe)
|
elseif st in (:surface, :wireframe)
|
||||||
plotattributes_out[:type] = "surface"
|
plotattributes_out[:type] = "surface"
|
||||||
|
|||||||
@ -73,7 +73,7 @@ function py_colormap(grad::ColorGradient)
|
|||||||
cm."set_bad"(color=(0,0,0,0.0), alpha=0.0)
|
cm."set_bad"(color=(0,0,0,0.0), alpha=0.0)
|
||||||
cm
|
cm
|
||||||
end
|
end
|
||||||
py_colormap(c) = py_colormap(cgrad())
|
py_colormap(c::Colorant) = py_colormap(_as_gradient(c))
|
||||||
|
|
||||||
|
|
||||||
function py_shading(c, z)
|
function py_shading(c, z)
|
||||||
@ -1013,6 +1013,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
cmap."set_array"([])
|
cmap."set_array"([])
|
||||||
handle = cmap
|
handle = cmap
|
||||||
end
|
end
|
||||||
|
kw[:spacing] = "proportional"
|
||||||
|
|
||||||
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
||||||
# note: the colorbar axis is positioned independently from the subplot axis
|
# note: the colorbar axis is positioned independently from the subplot axis
|
||||||
|
|||||||
76
src/utils.jl
76
src/utils.jl
@ -273,6 +273,9 @@ _cycle(v, indices::AVec{Int}) = fill(v, length(indices))
|
|||||||
_cycle(grad::ColorGradient, idx::Int) = _cycle(grad.colors, idx)
|
_cycle(grad::ColorGradient, idx::Int) = _cycle(grad.colors, idx)
|
||||||
_cycle(grad::ColorGradient, indices::AVec{Int}) = _cycle(grad.colors, indices)
|
_cycle(grad::ColorGradient, indices::AVec{Int}) = _cycle(grad.colors, indices)
|
||||||
|
|
||||||
|
_as_gradient(grad::ColorGradient) = grad
|
||||||
|
_as_gradient(c::Colorant) = ColorGradient([c,c])
|
||||||
|
|
||||||
makevec(v::AVec) = v
|
makevec(v::AVec) = v
|
||||||
makevec(v::T) where {T} = T[v]
|
makevec(v::T) where {T} = T[v]
|
||||||
|
|
||||||
@ -581,49 +584,48 @@ end
|
|||||||
|
|
||||||
_update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax)
|
_update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax)
|
||||||
|
|
||||||
function hascolorbar(series::Series)
|
@enum ColorbarStyle cbar_gradient cbar_fill cbar_lines
|
||||||
st = series[:seriestype]
|
|
||||||
hascbar = st == :heatmap
|
|
||||||
if st == :contour
|
|
||||||
hascbar = (isscalar(series[:levels]) ? (series[:levels] > 1) : (length(series[:levels]) > 1)) && (length(unique(Array(series[:z]))) > 1)
|
|
||||||
end
|
|
||||||
if series[:marker_z] != nothing || series[:line_z] != nothing || series[:fill_z] != nothing
|
|
||||||
hascbar = true
|
|
||||||
end
|
|
||||||
# no colorbar if we are creating a surface LightSource
|
|
||||||
if xor(st == :surface, series[:fill_z] != nothing)
|
|
||||||
hascbar = true
|
|
||||||
end
|
|
||||||
return hascbar
|
|
||||||
end
|
|
||||||
|
|
||||||
function hascolorbar(sp::Subplot)
|
function colorbar_style(series::Series)
|
||||||
cbar = sp[:colorbar]
|
colorbar_entry = series[:colorbar_entry]
|
||||||
hascbar = false
|
if !(colorbar_entry isa Bool)
|
||||||
if cbar != :none
|
@warn "Non-boolean colorbar_entry ignored."
|
||||||
for series in series_list(sp)
|
colorbar_entry = true
|
||||||
if hascolorbar(series)
|
|
||||||
hascbar = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
hascbar
|
|
||||||
end
|
if !colorbar_entry
|
||||||
|
nothing
|
||||||
function colorbar_levels(series::Series, clims)
|
elseif isfilledcontour(series)
|
||||||
if series[:seriestype] == :contour
|
cbar_fill
|
||||||
zmin, zmax = clims
|
elseif iscontour(series)
|
||||||
levels = series[:levels]
|
cbar_lines
|
||||||
levels isa AbstractArray ?
|
elseif series[:seriestype] ∈ (:heatmap,:surface) ||
|
||||||
levels :
|
any(series[z] !== nothing for z ∈ [:marker_z,:line_z,:fill_z])
|
||||||
levels > 1 ?
|
cbar_gradient
|
||||||
range(zmin, stop=zmax, length=levels) :
|
else
|
||||||
[(zmin + zmax) / 2]
|
|
||||||
else # including heatmap, surface
|
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hascolorbar(series::Series) = colorbar_style(series) !== nothing
|
||||||
|
hascolorbar(sp::Subplot) = sp[:colorbar] != :none && any(hascolorbar(s) for s in series_list(sp))
|
||||||
|
|
||||||
|
iscontour(series::Series) = series[:seriestype] == :contour
|
||||||
|
isfilledcontour(series::Series) = iscontour(series) && series[:fillrange] !== nothing
|
||||||
|
|
||||||
|
function contour_levels(series::Series, clims)
|
||||||
|
iscontour(series) || error("Not a contour series")
|
||||||
|
zmin, zmax = clims
|
||||||
|
levels = series[:levels]
|
||||||
|
if levels isa Integer
|
||||||
|
levels = range(zmin, stop=zmax, length=levels+2)
|
||||||
|
if !isfilledcontour(series)
|
||||||
|
levels = levels[2:end-1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
levels
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for comp in (:line, :fill, :marker)
|
for comp in (:line, :fill, :marker)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user