MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.4k stars 306 forks source link

Wrong units #4063

Open jariji opened 2 months ago

jariji commented 2 months ago
  [13f3f980] CairoMakie v0.12.5
  [1986cc42] Unitful v1.21.0

julia> scatter(rand(5)u"m/s", rand(5)u"m/s")

The units are wrong.

image

SimonDanisch commented 2 months ago

Why it switches to decimeter is because the default is to automatically switch to the best unit to represent the number range. Why it drops the second is not really clear to me... You could have a look at: https://github.com/MakieOrg/Makie.jl/blob/master/src/dim-converts/unitful-integration.jl And see where it goes wrong!

ffreyer commented 2 months ago

It's one of the base_unit() calls. https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/src/dim-converts/unitful-integration.jl#L14-L16 It goes through these 3 in order where in the last one U = (m, s^-1), so that indexing just grabs m

ffreyer commented 1 week ago

It looks like most of this is for adjusting unit prefixes to the range of numbers given. E.g. changing 10000m .. 54000m to 10km .. 54km. I wonder if we should just drop those conversions. It seems difficult to apply them to compound units - e.g. if you have "A * B / C", should A, B or C get a prefix? Some people may also supply specific prefixes on purpose because they are commonly used (e.g. g/cm^3). It also looks like this is not generic atm, i.e. we'd have to define valid prefixes for every unit and add special cases to avoid things like dft (deci-feet).

jariji commented 1 week ago

Yeah keeping the user's units seems good.

abhro commented 1 week ago

Is there an option to do it at the top (or right) of the axes? I mean in the style that MATLAB does power of 10 representations (linear plot, scaled), then putting the units on top of the axis might help (see first image of https://tutorial45.com/matlab-plot-colors-and-styles/)

aplavin commented 1 week ago

Agree, it would be both more familiar to many readers and less cluttered to show units once per axes – https://github.com/MakieOrg/Makie.jl/issues/3890.