Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Units in axis labels #3890

Open
aplavin opened this issue May 25, 2024 · 2 comments
Open

Units in axis labels #3890

aplavin opened this issue May 25, 2024 · 2 comments
Labels
documentation enhancement Feature requests and enhancements Makie Backend independent issues (Makie core) maybe outdated/fixed TODO: review units aka dim converts

Comments

@aplavin
Copy link
Contributor

aplavin commented May 25, 2024

Feature description

I didn't find an option to put units into axis labels instead of tick labels. Is it available anywhere?
Maybe that should also be the default? I very rarely see plots with units written at each tick label in practice, the most common way is to put them into axis labels.

For plot types, please add an image of how it should look like

Top: current Unitful support.
Bottom: how I'd really like it to look.
image

@aplavin aplavin added the enhancement Feature requests and enhancements label May 25, 2024
@DanDeepPhase
Copy link

DanDeepPhase commented May 25, 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)

@aplavin
Copy link
Contributor Author

aplavin commented May 26, 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.

@t-bltg t-bltg added the units aka dim converts label May 27, 2024
@ffreyer ffreyer added documentation maybe outdated/fixed TODO: review Makie Backend independent issues (Makie core) labels Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation enhancement Feature requests and enhancements Makie Backend independent issues (Makie core) maybe outdated/fixed TODO: review units aka dim converts
Projects
None yet
Development

No branches or pull requests

4 participants