How do I get the max value of the graph in `density(data?)`

(I want to plot a line on the plot to mark the mean value, as well as two other values. So I need to figure out about how big the plot area is in y-direction, so that the line covers the entire height of the plot(ish), but not more) (edited)

Call the kernel density estimation manually

https://github.com/JuliaStats/KernelDensity.jl

From that you can easily find the maximum.

Thanks!

How, exactly? I canâ€™t seem to find a way to access the internal array of the kde, and, something like

```
kd = kde(data)
maximum(kd)
```

doesnâ€™t have a matching methodâ€¦

You can use bisection on `pdf(kd, x) `

If you can fit a distribution using Distributions.jl, then you could compute its mode.

Its right in the read me of the KernelDensity.jl linked above

The

`UnivariateKDE`

object`U`

contains gridded coordinates (`U.x`

) and the density estimate (`U.density`

).

Just take the maximum of U.density

Thanks all, for your comments.

Thatâ€™s helpful, and is what the OP asked for, but just to add a bit for other new users trying to find the mode of the KDE, from its maximum value:

```
U = kde(data)
imax = findmax(U.density)[2]
U_mode = U.x[imax]
```

More generally, I think this is related to an open enhancement issue that would be great to see implemented.