From cc14ab20bb9e2678f1494cb264dc81187d7cb6fa Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 12:49:07 +0100 Subject: [PATCH 1/5] neglect clims for series without colorbar entry --- src/utils.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index bf478958..48eb1126 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -525,11 +525,13 @@ 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)...) + if series[:colorbar_entry] + 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 end end From 17eef46da2541981beb89047ca912cd83d23154e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 18:50:02 +0100 Subject: [PATCH 2/5] separate clims for colorbar_entry=false series for GR --- src/backends/gr.jl | 28 ++++------------------------ src/utils.jl | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 503172d5..84c9b24a 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 @@ -995,14 +980,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setlinewidth(sp.plt[:thickness_scaling]) if is3d(sp) - # TODO do we really need a different clims computation here from the one - # computed above using get_clims(sp)? - zmin, zmax = gr_lims(sp, zaxis, true) - clims3d = sp[:clims] - if is_2tuple(clims3d) - isfinite(clims3d[1]) && (zmin = clims3d[1]) - isfinite(clims3d[2]) && (zmax = clims3d[2]) - end GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 @@ -1234,6 +1211,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 +1449,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 +1477,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/utils.jl b/src/utils.jl index 48eb1126..0c2b4b80 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -523,16 +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) if series[:colorbar_entry] - 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 + zmin, zmax = _update_clims(zmin, zmax, get_clims(series)...) end end clims = sp[:clims] @@ -543,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 From b58c52f12ceca209a2a18733d577cd2e59533a18 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 18:54:01 +0100 Subject: [PATCH 3/5] per series clims for plotly --- src/backends/plotly.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 9b4a51c5bef5172473dd8981dd3435add28c3f8d Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 19:01:07 +0100 Subject: [PATCH 4/5] per series clims for pyplot() --- src/backends/pyplot.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"( From cf8bd786d0a8f123bcea430aef6326212e8d9931 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 19:40:56 +0100 Subject: [PATCH 5/5] readd deleted lines in GR --- src/backends/gr.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 84c9b24a..7aee8768 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -980,6 +980,14 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setlinewidth(sp.plt[:thickness_scaling]) if is3d(sp) + # TODO do we really need a different clims computation here from the one + # computed above using get_clims(sp)? + zmin, zmax = gr_lims(sp, zaxis, true) + clims3d = sp[:clims] + if is_2tuple(clims3d) + isfinite(clims3d[1]) && (zmin = clims3d[1]) + isfinite(clims3d[2]) && (zmax = clims3d[2]) + end GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2