Merge pull request #2230 from daschw/colorbar
Neglect clims of series with colorbar_entry=false
This commit is contained in:
commit
6b0e45c450
@ -260,19 +260,6 @@ function gr_fill_viewport(vp::AVec{Float64}, c)
|
|||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
normalize_zvals(args...) = nothing
|
|
||||||
function normalize_zvals(zv::AVec, clims::NTuple{2, <:Real})
|
|
||||||
vmin, vmax = ignorenan_extrema(zv)
|
|
||||||
isfinite(clims[1]) && (vmin = clims[1])
|
|
||||||
isfinite(clims[2]) && (vmax = clims[2])
|
|
||||||
if vmin == vmax
|
|
||||||
zeros(length(zv))
|
|
||||||
else
|
|
||||||
clamp.((zv .- vmin) ./ (vmax .- vmin), 0, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# draw ONE Shape
|
# draw ONE Shape
|
||||||
@ -920,8 +907,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# reduced from before... set some flags based on the series in this subplot
|
# reduced from before... set some flags based on the series in this subplot
|
||||||
# TODO: can these be generic flags?
|
# TODO: can these be generic flags?
|
||||||
outside_ticks = false
|
outside_ticks = false
|
||||||
# calculate the colorbar limits once for a subplot
|
|
||||||
clims = get_clims(sp)
|
|
||||||
cbar = GRColorbar()
|
cbar = GRColorbar()
|
||||||
|
|
||||||
draw_axes = sp[:framestyle] != :none
|
draw_axes = sp[:framestyle] != :none
|
||||||
@ -1234,6 +1219,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
x, y, z = series[:x], series[:y], series[:z]
|
x, y, z = series[:x], series[:y], series[:z]
|
||||||
frng = series[:fillrange]
|
frng = series[:fillrange]
|
||||||
|
|
||||||
|
clims = get_clims(sp, series)
|
||||||
|
|
||||||
# add custom frame shapes to markershape?
|
# add custom frame shapes to markershape?
|
||||||
series_annotations_shapes!(series)
|
series_annotations_shapes!(series)
|
||||||
# -------------------------------------------------------
|
# -------------------------------------------------------
|
||||||
@ -1470,7 +1457,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# draw the colorbar
|
# draw the colorbar
|
||||||
hascolorbar(sp) && gr_draw_colorbar(cbar, sp, clims)
|
hascolorbar(sp) && gr_draw_colorbar(cbar, sp, get_clims(sp))
|
||||||
|
|
||||||
# add the legend
|
# add the legend
|
||||||
if sp[:legend] != :none
|
if sp[:legend] != :none
|
||||||
@ -1498,6 +1485,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
gr_set_font(legendfont(sp))
|
gr_set_font(legendfont(sp))
|
||||||
end
|
end
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
|
clims = get_clims(sp, series)
|
||||||
should_add_to_legend(series) || continue
|
should_add_to_legend(series) || continue
|
||||||
st = series[:seriestype]
|
st = series[:seriestype]
|
||||||
lc = get_linecolor(series, clims)
|
lc = get_linecolor(series, clims)
|
||||||
|
|||||||
@ -454,7 +454,7 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
st = series[:seriestype]
|
st = series[:seriestype]
|
||||||
|
|
||||||
sp = series[:subplot]
|
sp = series[:subplot]
|
||||||
clims = get_clims(sp)
|
clims = get_clims(sp, series)
|
||||||
|
|
||||||
if st == :shape
|
if st == :shape
|
||||||
return plotly_series_shapes(plt, series, clims)
|
return plotly_series_shapes(plt, series, clims)
|
||||||
|
|||||||
@ -399,7 +399,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
# handle zcolor and get c/cmap
|
# handle zcolor and get c/cmap
|
||||||
needs_colorbar = hascolorbar(sp)
|
needs_colorbar = hascolorbar(sp)
|
||||||
vmin, vmax = clims = get_clims(sp)
|
vmin, vmax = clims = get_clims(sp, series)
|
||||||
|
|
||||||
# Dict to store extra kwargs
|
# Dict to store extra kwargs
|
||||||
if st == :wireframe
|
if st == :wireframe
|
||||||
@ -1290,13 +1290,13 @@ py_legend_bbox(pos) = pos
|
|||||||
|
|
||||||
function py_add_legend(plt::Plot, sp::Subplot, ax)
|
function py_add_legend(plt::Plot, sp::Subplot, ax)
|
||||||
leg = sp[:legend]
|
leg = sp[:legend]
|
||||||
clims = get_clims(sp)
|
|
||||||
if leg != :none
|
if leg != :none
|
||||||
# gotta do this to ensure both axes are included
|
# gotta do this to ensure both axes are included
|
||||||
labels = []
|
labels = []
|
||||||
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)
|
||||||
|
clims = get_clims(sp, series)
|
||||||
# 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"(
|
||||||
|
|||||||
36
src/utils.jl
36
src/utils.jl
@ -523,14 +523,9 @@ zlims(sp_idx::Int = 1) = zlims(current(), sp_idx)
|
|||||||
|
|
||||||
function get_clims(sp::Subplot)
|
function get_clims(sp::Subplot)
|
||||||
zmin, zmax = Inf, -Inf
|
zmin, zmax = Inf, -Inf
|
||||||
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface)
|
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z])
|
if series[:colorbar_entry]
|
||||||
if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real})
|
zmin, zmax = _update_clims(zmin, zmax, get_clims(series)...)
|
||||||
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...)
|
|
||||||
elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real})
|
|
||||||
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
@ -541,6 +536,33 @@ function get_clims(sp::Subplot)
|
|||||||
return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1)
|
return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function get_clims(sp::Subplot, series::Series)
|
||||||
|
zmin, zmax = if series[:colorbar_entry]
|
||||||
|
get_clims(sp)
|
||||||
|
else
|
||||||
|
get_clims(series)
|
||||||
|
end
|
||||||
|
clims = sp[:clims]
|
||||||
|
if is_2tuple(clims)
|
||||||
|
isfinite(clims[1]) && (zmin = clims[1])
|
||||||
|
isfinite(clims[2]) && (zmax = clims[2])
|
||||||
|
end
|
||||||
|
return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_clims(series::Series)
|
||||||
|
zmin, zmax = Inf, -Inf
|
||||||
|
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface)
|
||||||
|
for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z])
|
||||||
|
if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real})
|
||||||
|
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...)
|
||||||
|
elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real})
|
||||||
|
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1)
|
||||||
|
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)
|
||||||
|
|
||||||
@enum ColorbarStyle cbar_gradient cbar_fill cbar_lines
|
@enum ColorbarStyle cbar_gradient cbar_fill cbar_lines
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user