diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 503172d5..7aee8768 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -260,19 +260,6 @@ function gr_fill_viewport(vp::AVec{Float64}, c) GR.restorestate() 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 @@ -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 # TODO: can these be generic flags? outside_ticks = false - # calculate the colorbar limits once for a subplot - clims = get_clims(sp) cbar = GRColorbar() 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] frng = series[:fillrange] + clims = get_clims(sp, series) + # add custom frame shapes to markershape? series_annotations_shapes!(series) # ------------------------------------------------------- @@ -1470,7 +1457,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end # draw the colorbar - hascolorbar(sp) && gr_draw_colorbar(cbar, sp, clims) + hascolorbar(sp) && gr_draw_colorbar(cbar, sp, get_clims(sp)) # add the legend if sp[:legend] != :none @@ -1498,6 +1485,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_font(legendfont(sp)) end for series in series_list(sp) + clims = get_clims(sp, series) should_add_to_legend(series) || continue st = series[:seriestype] lc = get_linecolor(series, clims) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 4a604889..4fcb334f 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -454,7 +454,7 @@ function plotly_series(plt::Plot, series::Series) st = series[:seriestype] sp = series[:subplot] - clims = get_clims(sp) + clims = get_clims(sp, series) if st == :shape return plotly_series_shapes(plt, series, clims) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 27ce9a4c..0b36999b 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -399,7 +399,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # handle zcolor and get c/cmap needs_colorbar = hascolorbar(sp) - vmin, vmax = clims = get_clims(sp) + vmin, vmax = clims = get_clims(sp, series) # Dict to store extra kwargs if st == :wireframe @@ -1290,13 +1290,13 @@ py_legend_bbox(pos) = pos function py_add_legend(plt::Plot, sp::Subplot, ax) leg = sp[:legend] - clims = get_clims(sp) if leg != :none # gotta do this to ensure both axes are included labels = [] handles = [] for series in series_list(sp) if should_add_to_legend(series) + clims = get_clims(sp, series) # add a line/marker and a label push!(handles, if series[:seriestype] == :shape || series[:fillrange] !== nothing pypatches."Patch"( diff --git a/src/utils.jl b/src/utils.jl index bf478958..0c2b4b80 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -523,14 +523,9 @@ zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) function get_clims(sp::Subplot) zmin, zmax = Inf, -Inf - z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) 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 (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 + if series[:colorbar_entry] + zmin, zmax = _update_clims(zmin, zmax, get_clims(series)...) end end clims = sp[:clims] @@ -541,6 +536,33 @@ function get_clims(sp::Subplot) return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1) 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) @enum ColorbarStyle cbar_gradient cbar_fill cbar_lines