forked from JuliaPlots/Plots.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Colorbar enhancements (JuliaPlots#3346)
* CompatHelper: bump compat for "Showoff" to "1.0" * fix series-segments for empty series * fix wireframe on pyplot * colorbar redesign * minimal working version * reduce code duplication for colorbar ticks * fix aspect_ratio in GR with legend=:outertopright * fix GR test failure * new release [skip ci] * colorbar scale supported * Added weights example to ? histogram Helps to clarify the use of weights (which differs from StatsBase functions) * Update precompile_*.jl file * minor version bump [skip ci] * working prototype * fixed formatting, added colorbar docs * colorbar redesign * minimal working version * reduce code duplication for colorbar ticks * fix GR test failure * colorbar scale supported * working prototype * fixed formatting, added colorbar docs Co-authored-by: Daniel Schwabeneder <daschw@disroot.org>
- Loading branch information
1 parent
9fc1d57
commit c0824bd
Showing
9 changed files
with
532 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# These functions return an operator for use in `get_clims(::Seres, op)` | ||
process_clims(lims::Tuple{<:Number,<:Number}) = (zlims -> ifelse.(isfinite.(lims), lims, zlims)) ∘ ignorenan_extrema | ||
process_clims(s::Union{Symbol,Nothing,Missing}) = ignorenan_extrema | ||
# don't specialize on ::Function otherwise python functions won't work | ||
process_clims(f) = f | ||
|
||
function get_clims(sp::Subplot, op=process_clims(sp[:clims])) | ||
zmin, zmax = Inf, -Inf | ||
for series in series_list(sp) | ||
if series[:colorbar_entry] | ||
zmin, zmax = _update_clims(zmin, zmax, get_clims(series, op)...) | ||
end | ||
end | ||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) | ||
end | ||
|
||
function get_clims(sp::Subplot, series::Series, op=process_clims(sp[:clims])) | ||
zmin, zmax = if series[:colorbar_entry] | ||
get_clims(sp, op) | ||
else | ||
get_clims(series, op) | ||
end | ||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) | ||
end | ||
|
||
""" | ||
get_clims(::Series, op=Plots.ignorenan_extrema) | ||
Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`, | ||
which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite | ||
values of the input. | ||
""" | ||
function get_clims(series::Series, op=ignorenan_extrema) | ||
zmin, zmax = Inf, -Inf | ||
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface, :hexbin) | ||
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, op(vals.surf)...) | ||
elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real}) | ||
zmin, zmax = _update_clims(zmin, zmax, op(vals)...) | ||
end | ||
end | ||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN) | ||
end | ||
|
||
_update_clims(zmin, zmax, emin, emax) = NaNMath.min(zmin, emin), NaNMath.max(zmax, emax) | ||
|
||
@enum ColorbarStyle cbar_gradient cbar_fill cbar_lines | ||
|
||
function colorbar_style(series::Series) | ||
colorbar_entry = series[:colorbar_entry] | ||
if !(colorbar_entry isa Bool) | ||
@warn "Non-boolean colorbar_entry ignored." | ||
colorbar_entry = true | ||
end | ||
|
||
if !colorbar_entry | ||
nothing | ||
elseif isfilledcontour(series) | ||
cbar_fill | ||
elseif iscontour(series) | ||
cbar_lines | ||
elseif series[:seriestype] ∈ (:heatmap,:surface) || | ||
any(series[z] !== nothing for z ∈ [:marker_z,:line_z,:fill_z]) | ||
cbar_gradient | ||
else | ||
nothing | ||
end | ||
end | ||
|
||
hascolorbar(series::Series) = colorbar_style(series) !== nothing | ||
hascolorbar(sp::Subplot) = sp[:colorbar] != :none && any(hascolorbar(s) for s in series_list(sp)) | ||
|
||
function get_colorbar_ticks(sp::Subplot; update = true) | ||
if update || !haskey(sp.attr, :colorbar_optimized_ticks) | ||
ticks = _transform_ticks(sp[:colorbar_ticks]) | ||
cvals = sp[:colorbar_continuous_values] | ||
dvals = sp[:colorbar_discrete_values] | ||
clims = get_clims(sp) | ||
scale = sp[:colorbar_scale] | ||
formatter = sp[:colorbar_formatter] | ||
sp.attr[:colorbar_optimized_ticks] = | ||
get_ticks(ticks, cvals, dvals, clims, scale, formatter) | ||
end | ||
return sp.attr[:colorbar_optimized_ticks] | ||
end | ||
|
||
function _update_subplot_colorbars(sp::Subplot) | ||
# Dynamic callback from the pipeline if needed | ||
end |
Oops, something went wrong.