# Plotting a distribution

Trying to plot normal distributions from the Distributions package. How do I do this?

julia> normalDist = fit(Normal, data)

Normal{Float64}(μ=100.3434334, σ=0.05)

julia> plot(normalDist)

ERROR: No user recipe defined for Normal{Float64}

Which plotting package is this? Try `StatsPlots` https://github.com/JuliaPlots/StatsPlots.jl/blob/master/README.md

It is unclear what you want to plot for a distribution. The pdf, the cdf, or something else? In any case, here is a PGFPlotsX example:

``````using PGFPlotsX, Distributions

d = Normal(100.3434334, 0.05)
lo, hi = quantile.(d, [0.01, 0.99])
x = range(lo, hi; length = 100)
@pgf Axis({ xlabel = "x", ylabel = "pdf" },
Plot({thick, blue }, Table(x, pdf.(d, x))))
@pgf Axis({ xlabel = "x", ylabel = "cdf" },
Plot({thick, blue }, Table(x, cdf.(d, x))))
``````

4 Likes

Thank You! StatsPlots works as expected. I was trying the standard Plots package.

Hi, don’t know if there’s still any trouble on this, but you can plot a distribuition using the normal Plots package now. You only have to declare a plot() variable and call it using the distribuition as a parameter. Ex:
p = Plots.plot()
Plots.plot!(p,Geometric(0.6))

Are you sure? Using latest Plots.jl version but still need to get the Distributions’ recipes from StatsPlots:

``````using StatsPlots, Distributions
plot(Geometric(0.6))
``````
1 Like

Same for me on the latest Plots release:

``````(jl_P3u1qh) pkg> st
Status `...\Temp\jl_P3u1qh\Project.toml`
[31c24e10] Distributions v0.25.34
[91a5bcdd] Plots v1.24.3

julia> using Plots, Distributions

julia> plot(Geometric(0.6))
ERROR: Cannot convert Geometric{Float64} to series data for plotting
``````
1 Like