Giter Club home page Giter Club logo

Comments (2)

DanDeepPhase avatar DanDeepPhase commented on June 20, 2024

I found this in the code:

Fix unit to always use Meter & display unit in the xlabel:
```julia
uc = Makie.UnitfulConversion(u"m"; units_in_label=false)
scatter(1:4, [0.01u"km", 0.02u"km", 0.03u"km", 0.04u"km"]; axis=(dim2_conversion=uc, xlabel="x (km)"))
```

The example is a little wrong, because it hides units for Y and then labels them in X, but this works for your example:

f=Figure()
ax=Axis(f[1,1], 
    dim1_conversion=Makie.UnitfulConversion(u"m"; units_in_label=false),
    xlabel="Distance (m)",
    dim2_conversion=Makie.UnitfulConversion(u"W"; units_in_label=false),
    ylabel="Power (W)",)
mak = scatter!(ax,(1:5)u"m", (10:10:50)u"W")

Not sure if there is a simpler way. It does retain the units in the axis, so following up with same dimension units works.

mak2 = scatter!(ax, (100:100:500)u"cm", (0.005:0.010:0.045)kW)

from makie.jl.

aplavin avatar aplavin commented on June 20, 2024

Yes, seems like specifying dimconversions manually works, but is very verbose for something wanted in (presumably) the vast majority of cases.
Wonder what's the reason for making units a part of ticklabels: are there some fields where such plots are more common than those with units in axislabels?

Maybe something like this is possible, what do you think?

let
	fig = Figure()
	ax = Axis(fig[1,1], units_in_axislabels="(%s)")  # common alternative values are "[%s]" and  ", %s"
	scatter!(ax, (1:5)u"m", (10:10:50)u"kW")
	fig
end

This would put units into axislabels using the provided pattern.

from makie.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.