JuliaPlots / StatsPlots.jl

Statistical plotting recipes for Plots.jl
Other
436 stars 88 forks source link

wrong ylims in marginalhist #178

Open dkarrasch opened 6 years ago

dkarrasch commented 6 years ago

I computed two very long vectors of positive numbers between 0 and 10, and wanted to plot a marginalhist, but the y-axis was way off. It's fixable by setting xlims=extrema(x), ylims=extrema(y), but then the marginal distributions seem to be wrong (localized in two points or so).

mkborregaard commented 6 years ago

That doesn't sound good, thanks for reporting. Would you mind posting the plot and code here?

dkarrasch commented 6 years ago

The way I generated the vectors depends on many other things, but here is some metadata:

julia> length(D1) # same for D2, generate via D1 = 10*rand(4803450) ?
4803450

julia> typeof(D1) # same for D2
Array{Float64,1}

julia> extrema(D1)
(3.959910238949063e-5, 10.713477888315648)

julia> extrema(D2)
(0.0, 10.524203396302019)

julia> marginalhist(D1, D2, fc = :plasma, bins=200)

yields marginalhist Calling

julia> marginalhist(D1, D2, fc = :plasma, xlims=extrema(D1), ylims=extrema(D2), bins=200)

yields marginalhist2 So, in the first case the marginal distributions seem to correct, but the 2d field of vision is way off, in the second case the 2d field is good, but the marginal distributions seem to be wrong.

mkborregaard commented 6 years ago

Wow :-O Thanks for reporting.

piever commented 6 years ago

Thanks for reporting! It'd be very helpful, in order to reproduce your error to have some code that we can just copy paste and run to get one of this wrong plots and to know what version of Plots, StatPlots and Julia you are using.

dkarrasch commented 6 years ago

I'm on the run, but the following seems to produce the error:

D1 = 10*rand(4803450)
D2 = 10*rand(4803450)
marginalhist(D1, D2, fc = :plasma, bins=200)

Here's some more info.

julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = atom -a

and

(v1.0) pkg> st
    Status `~/.julia/environments/v1.0/Project.toml`
  [7d9fca2a] Arpack v0.2.3
  [c52e3926] Atom v0.7.5
  [6e4b80f9] BenchmarkTools v0.4.0
  [5ae59095] Colors v0.9.4
  [b4f34e82] Distances v0.7.3
  [e30172f5] Documenter v0.19.6
  [5789e2e9] FileIO v1.0.1
  [6218d12a] ImageMagick v0.7.1
  [916415d5] Images v0.15.1
  [42fd0dbc] IterativeSolvers v0.7.1
  [033835bb] JLD2 v0.1.1
  [30d91d44] JuAFEM v0.2.0 #master (https://github.com/KristofferC/JuAFEM.jl.git)
  [e5e0dc1b] Juno v0.5.2
  [7a12625a] LinearMaps v2.2.0
  [1dea7af3] OrdinaryDiffEq v4.11.0
  [91a5bcdd] Plots v0.20.1
  [dca85d43] QuartzImageIO v0.5.0
  [60ddc479] StatPlots v0.8.0
  [90137ffa] StaticArrays v0.8.3
  [9449cd9e] TSVD v0.3.0
  [48a634ad] Tensors v1.0.0

Hope this helps... and thanks for looking into it!

dkarrasch commented 6 years ago

The issue seems to be with the number of elements in the vectors.

marginalhist(10*rand(1000000), 22*rand(1000000))

works, whereas

marginalhist(10*rand(10000000), 22*rand(10000000))

doesn't. Strangely enough,

histogram2d(10*rand(10000000), 22*rand(10000000))

which seems to be called for the main plot in marginalhist, works fine, and even

histogram2d(10*rand(100000000), 22*rand(100000000))

does.

piever commented 6 years ago

It seems there are two issues:

  1. density is broken with orientation = :horizontal (doesn't depend on marginalhist)
  2. the computation of xlims and ylims gets really funky in marginalhist

@mkborregaard : do you know where the computation of xlims and ylims happen in Plots?

mkborregaard commented 6 years ago

In PlotUtils, axis.jl.

piever commented 6 years ago

Some things are really hard to understand here though. For example, why the marginalized distribution are plotted as density (line plot) whereas the series is instructed to do a histogram (see here , density defaults to false).

dkarrasch commented 6 years ago

I encountered a probably very related issue, which occurs after modifying the axis limits.

marginalhist(randn(10000), randn(10000), aspect_ratio=1)

Again, the marginal distributions essentially break down.