Density plot from dataframe column in Makie

173 views Asked by At

I am, unsuccessfully, trying to create a density plot with CairoMakie based on a column of a dataframe.

using CairoMakie CairoMakie.density(Rawdata.LVEDV) MethodError: no method matching kde(::Vector{Any}; npoints=200)

When I ckeck the type of "Rawdata.LVEDV" the result is: Vector{Any} (alias for Array{Any, 1})

typeof(Rawdata.LVEDV) Vector{Any} (alias for Array{Any, 1}) Rawdata.LVEDV 309-element Vector{Any}: first(Rawdata.LVEDV, 5) 147 161 160 104 127

What am I doing wrong? Apologies if this is too easy but I do not get it.

1

There are 1 answers

1
AKdemy On

You seem to have mixed data types (e.g. float and strings). Look at the entire vector not just the first entries.

f = Figure()
Axis(f[1, 1])

test = ["4", 5,3.2, 10, randn(200)...]
CairoMakie.density!(test)
f

vs

f = Figure()
Axis(f[1, 1])
CairoMakie.density!(randn(200))
f

Edit

If you really have only integers, I highly recommend you look at your code in more detail. Julia should not use Any for Int, as this will slow down Julia like crazy (no type inference will be possible anymore).

Just run

df = DataFrame(test = collect(1:1:100))
df.test 

This should be a vector of Int64. You can run unique(typeof.(df.test)) to see the data types in your vector. In your case unique(typeof.(Rawdata.LVEDV)).