Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corner plot issue #457

Closed
yebai opened this issue May 23, 2024 · 3 comments
Closed

corner plot issue #457

yebai opened this issue May 23, 2024 · 3 comments

Comments

@yebai
Copy link
Member

yebai commented May 23, 2024

The following example errors. It seems the issue is from upper stream packages instead of MCMCChains.

Note that the corner plot works fine when the number of variables is smaller than 3.

julia> val = rand(500, 4, 3);

julia> chn = Chains(val, [:a, :b, :c, :d]);

julia> corner(chn)


ERROR: The sum of widths must be 1!
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] Plots.GridLayout(::Int64, ::Vararg{…}; parent::Plots.RootLayout, widths::Vector{…}, heights::Vector{…}, kw::@Kwargs{})
    @ Plots ~/.julia/packages/Plots/ju9dp/src/layouts.jl:232
  [3] grid(::Int64, ::Vararg{Int64}; kw::@Kwargs{widths::Vector{Float64}, heights::Vector{Float64}})
    @ Plots ~/.julia/packages/Plots/ju9dp/src/layouts.jl:209
  [4] macro expansion
    @ ~/.julia/packages/StatsPlots/cStOe/src/cornerplot.jl:29 [inlined]
  [5] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, cp::StatsPlots.CornerPlot)
    @ StatsPlots ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
  [6] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/ju9dp/src/plot.jl:223
  [9] #plot#188
    @ ~/.julia/packages/Plots/ju9dp/src/plot.jl:102 [inlined]
 [10] plot
    @ ~/.julia/packages/Plots/ju9dp/src/plot.jl:93 [inlined]
 [11] corner(args::Chains{Float64, AxisArrays.AxisArray{…}, Missing, @NamedTuple{…}, @NamedTuple{}})
    @ MCMCChains ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:427
 [12] top-level scope
    @ REPL[53]:1
Some type information was truncated. Use `show(err)` to see complete types.
@penelopeysm
Copy link
Member

penelopeysm commented Aug 21, 2024

I looked into this, and it's a classic problem. Plots.jl checks that the widths add up to 1 using:

        if sum(widths) != 1
            error("The sum of widths must be 1!")
        end

With the example in the docs

using MCMCChains
using StatsPlots

# Define the experiment
n_iter = 100
n_name = 3
n_chain = 2

# experiment results
val = randn(n_iter, n_name, n_chain) .+ [1, 2, 3]'
val = hcat(val, rand(1:2, n_iter, 1, n_chain))

# construct a Chains object
chn = Chains(val, [:A, :B, :C, :D])

corner(chn)

it turns out that

widths = [0.3, 0.3, 0.3, 0.1]

and ...

julia> 0.3 + 0.3 + 0.3 + 0.1
0.9999999999999999

@penelopeysm
Copy link
Member

Upstream PR: JuliaPlots/Plots.jl#4972

@penelopeysm
Copy link
Member

Merged now, will be fixed with the next release of Plots.jl

@yebai yebai closed this as completed Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants