JuliaPlots / StatsPlots.jl

Statistical plotting recipes for Plots.jl
Other
440 stars 90 forks source link

Improvements to plotting PMFs for discrete distributions #451

Closed sethaxen closed 3 years ago

sethaxen commented 3 years ago

This PR fixes #450 and fixes #287.

devmotion commented 3 years ago

I think it would be easier (and probably faster) to not use detault_range but

sethaxen commented 3 years ago

Maybe it would be a good opportunity to address #287 as well.

Done!

julia> plot(Binomial(50, 0.5))

d

sethaxen commented 3 years ago

I made the same work for discrete mixtures. e.g. here is zero-inflated Poisson:

julia> zip = MixtureModel([Dirac(0), Poisson(10)], [0.1, 0.9])
MixtureModel{Distribution{Univariate, Discrete}}(K = 2)
components[1] (prior = 0.1000): Dirac{Int64}(value=0)
components[2] (prior = 0.9000): Poisson{Float64}(λ=10.0)

julia> plot(zip)
julia> plot(zip; components=false)
sethaxen commented 3 years ago

I wonder if one has to include markers for :sticks by default?

Can you clarify what you mean?

devmotion commented 3 years ago

If it is necessary to set markershape or if one should just not plot markers with the default settings.

sethaxen commented 3 years ago

If it is necessary to set markershape or if one should just not plot markers with the default settings.

Setting markershape is necessary to show the markers as suggested in the original issue. Personally, I prefer hair plots without markers and would prefer the simplicity of not explicitly showing them and letting the user do it if they want it. What do you think?

devmotion commented 3 years ago

Personally, I prefer hair plots without markers and would prefer the simplicity of not explicitly showing them and letting the user do it if they want it.

Yes, my question was if you think it would be preferrable to not show them explicitly. I prefer the version without markers (IMO it is a bit cleaner, in particular if there are many values to plot) and it seems simple enough to specify markershape if one wants to plot points as well.

sethaxen commented 3 years ago

Okay, I simplified the implementation to not show markers by default.

julia> plot(Binomial(50, 0.5))

For plots with few points, in my view this looks worse:

julia> plot(plot(Binomial(5, 0.1)), plot(Binomial(5, 0.1); markershape=:circle))

But it looks much better for plots with many points:

julia> plot(plot(Poisson(500)), plot(Poisson(500); markershape=:circle); legend=:left)