JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.82k stars 348 forks source link

[BUG] Inconsistent and erroneous treatment of fillrange #4075

Open baggepinnen opened 2 years ago

baggepinnen commented 2 years ago

The following produces strange results that differ between backends. I'd like the plot to look similar to the GR version, but with the fill upper area extending vertically similar to how the lower fill range does

Details

struct SettlingTimeObjective
    final_value::Float64
    time::Float64
    tolerance::Float64
end

@recipe function plot(o::SettlingTimeObjective)
    primary --> false
    linestyle --> :dash
    color --> :red
    fillalpha --> 0.5
    seriesalpha --> 0.5
    @series begin
        fillrange --> 0
        [o.time, 10*o.time], [o.final_value-o.tolerance, o.final_value-o.tolerance]
    end
    @series begin
        fillrange --> Inf
        [o.time, 10*o.time], [o.final_value+o.tolerance, o.final_value+o.tolerance]
    end
end

plot(randn(15))
plot!(SettlingTimeObjective(1, 5, 0.2))

Backends

GR

fill_gr

Plotly

fill_plotly

Versions

Plots.jl version: Plots v1.25.6 Backend version (]st -m <backend(s)>): Output of versioninfo():

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 9 5900X 12-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, znver3)
Environment:
  JULIA_NUM_THREADS = 12
  JULIA_EDITOR = code
  JULIA_SSH_NO_VERIFY_HOSTS = gitlab.cognibotics.net
  JULIA_PKG_PRECOMPILE_AUTO = 1
  JULIA_NUM_PRECOMPILE_TASKS = 6
BeastyBlacksmith commented 2 years ago

I get different results for GR fillrangeInf

I think, the question here is, what fillrange = Inf should do?

EDIT: funniliy that upper fillrange was not visible in the GTK Window, only in the png file

baggepinnen commented 2 years ago

I produced the plots in vscode, they might go through slightly different pipeline? I also used a non-random blue series but made it randn for the MWE. I expected fillrange = Inf to just extend upwards indefinitely, but not contribute to the default ylims.

In general, is there a way to indicate that an @series should not contribute to setting the axis limits? This is often useful when adding "guide lines" etc. that should always be there no matter the limits, i.e., their extent is infinite. hline/vline works this way IIUC and those are very useful, but are not always applicable, e.g., for semi-infinite lines etc.

BeastyBlacksmith commented 2 years ago

Yeah, vscode shows png files by default

BeastyBlacksmith commented 2 years ago

n general, is there a way to indicate that an @series should not contribute to setting the axis limits? This is often useful when adding "guide lines" etc. that should always be there no matter the limits, i.e., their extent is infinite. hline/vline works this way IIUC and those are very useful, but are not always applicable, e.g., for semi-infinite lines etc.

For lines there is seriestype := :straightline. https://github.com/JuliaPlots/Plots.jl/blob/46e19d9ad57fb21c6f6e1bb59ddf6473314cec9e/src/recipes.jl#L1625