JuliaPlots / Plots.jl

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

[BUG] cornerplot y-axis is too large #5007

Open Jonas-a-Zimmermann opened 1 month ago

Jonas-a-Zimmermann commented 1 month ago

Details

The y-lims in the cornerplot subfigures are too large, rendering the scatterplot and row-wise histograms useless. e.g.

using Random, Plots, StatsPlots
x, y = randn(1000), randn(1000)
cornerplot([x;;y]; compact=false)

leads to GRNotCompactPlot

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: Backend version: GR v0.73.8, PlotlyJS v0.18.14 Output of versioninfo(): Julia Version 1.10.5 Commit 6f3fdf7b362 (2024-08-27 14:19 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: macOS (arm64-apple-darwin22.4.0) CPU: 14 × Apple M3 Max WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)

Jonas-a-Zimmermann commented 1 month ago

A (naive) fix for this is to add the xlims and ylims in the cornerplot, as e.g.

# scatters
    for i = 1:N
        vi = view(mat, :, i)
        for j = 1:N
            # only the lower triangle
            if compact && i <= j
                continue
            end

            vj = view(mat, :, j)
            @series begin
                ticks := :auto
                if i == N
                    xformatter := :auto
                    xguide := _cycle(labs, j)
                end
                if j == 1
                    yformatter := :auto
                    yguide := _cycle(labs, i)
                end
                seriestype := :scatter
                subplot := indices[i + 1 - k, j]
                markercolor := grad[0.5 + 0.5C[i, j]]
                smooth --> true
                markerstrokewidth --> 0
                xlims --> extrema(vj).*1.05
                ylims --> extrema(vi).*1.05
                vj, vi
            end
        end
        # end
    end

leading to the desired outcome GRNotCompactPlotFix

Jonas-a-Zimmermann commented 3 weeks ago

After some digging I came to the conclusion that the cause of the issue is the usage of the depracted orientation in the definition of the histogram series (to clarify: line 71 of cornerplot.jl). After changing it to permute, it works as expected. However, the histograms on the right corner suffer from the same issue as in https://github.com/JuliaPlots/Plots.jl/issues/4949 .

Jonas-a-Zimmermann commented 3 weeks ago

While it also suffers from #4949 , there is the more intricate and serious issue of expand_extrema not fixing the lower limits of the (post permute)x-axis. This is set during the bar recipe. I believe the best course of action would be to just not handle axis widening during recipes. With expand_extrema!(axis, scale_lims(ignorenan_extrema(xseg.pts)..., default_widen_factor)) in the bar recipe Incorrect_Lower_bounds

Without expand_extrema!(axis, scale_lims(ignorenan_extrema(xseg.pts)..., default_widen_factor)) in the bar recipe Correct_Lower_Bounds