Code Monkey home page Code Monkey logo

Comments (5)

jw3126 avatar jw3126 commented on May 18, 2024

I am not really familiar with StatsPlots.jl, but if you want to tackle this issue I am happy to help with the UnitfulRecipes.jl side. My guess is that kde first performs a calculation (estimating kernel density) and then does some plotting stuff.
And the calculation is probably not compatible with units? Then one approach would be to make the calculation compatible with Unitful.jl I think and afterwards unitful plotting magically works hopefully.

from unitfulrecipes.jl.

gustaphe avatar gustaphe commented on May 18, 2024

The issue is that KernelDensity.kde() only accepts Real, while Unitful.Quantity isa Number but not a Real.

One solution to this and several similar bugs is a pretty invasive rework of Unitful with

struct RealQuantity{T<:Real, D, U} <: Real
    val::T
end
RealQuantity(q::Q) where {Q<:Unitful.Quantity} = RealQuantity{Q.parameters...}(q.val)

Another is to make kde more permissive, using isreal rather than dispatching with Real if that's important.

from unitfulrecipes.jl.

jmtlawrie avatar jmtlawrie commented on May 18, 2024

I am not really familiar with StatsPlots.jl, but if you want to tackle this issue I am happy to help with the UnitfulRecipes.jl side.

  • Thank you for the kind offer. Step one for me is to learn how generic Plots.jl recipes work, then UnitfulRecipes, so it might be a while yet 😄

My guess is that kde first performs a calculation (estimating kernel density) and then does some plotting stuff. And the calculation is probably not compatible with units?

  • I think this is also the case. Does this mean that the Plots.jl plot types all have methods which permit Unitful data?

Then one approach would be to make the calculation compatible with Unitful.jl I think and afterwards unitful plotting magically works hopefully.

  • If this is the right thing to do, I think this will be a thing to take to StatsPlots.jl in the first instance, and then return to UnitfulRecipes if needed afterward.

from unitfulrecipes.jl.

jmtlawrie avatar jmtlawrie commented on May 18, 2024

One solution to this and several similar bugs is a pretty invasive rework of Unitful

  • Thanks for your feedback!
  • Good to know, though such a step is definitely beyond me (I'm an engineer rather than programmer) and I am unsure if anyone else is interested in using the StatsPlots functionality with Unitful data directly.
  • Is this something that should be mentioned to the people who maintain Unitful, do you think?

In the meantime, I was able to plot what I was trying to, by, for example, doing a groupedbar() plot with data without any units, then I needed to plot a hline() on to this plot, which works very nicely with UnitfulRecipes, and lets the axes be scaled and the units be put onto the axes automatically with unitformat=:square or similar.

I intend to learn more about how this works in the future, at which point perhaps I can contribute something 🤞

from unitfulrecipes.jl.

gustaphe avatar gustaphe commented on May 18, 2024

Does this mean that the Plots.jl plot types all have methods which permit Unitful data?

It's rather that through our recipes, we are telling Plots how to convert Unitful data to unitless data before any plotting is done. I can't quite figure out why no such transformation is applied for StatsPlots.

from unitfulrecipes.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.