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

Support Unitful xticks and yticks? #55

Closed
JeffFessler opened this issue Jun 17, 2021 · 1 comment
Closed

Support Unitful xticks and yticks? #55

JeffFessler opened this issue Jun 17, 2021 · 1 comment

Comments

@JeffFessler
Copy link
Contributor

Thanks for this great package. Currently it supports Unitful xlim very nicely, but Unitful xticks leads to an error. This caught me because I often use xticks=[x[1],x[end]] to streamline plots and it fails if x has units. My workaround is xticks=[x[1],x[end]] / oneunit(x[1]) which is fine for now but I wanted to report the issue because it seems like it would be nicely consistent to support having the ticks be specified in the same units as the corresponding axis.

using Unitful, UnitfulRecipes, Plots 
x = 1u"mm" * (1:30)
scatter(x, 2x) # works as expected
scatter(x, 2x; xlim=(10u"mm", 20u"mm")) # works as expected!
scatter(x, 2x; xlim=(1u"cm", 2u"cm")) # works as expected - yay!
scatter(x, 2x; xticks=[1u"cm", 2u"cm"]) # error message

ERROR: DimensionError: 0.13 and 1.0 cm are not dimensionally compatible.
@jw3126
Copy link
Owner

jw3126 commented Jun 17, 2021

Thanks for reporting. Would be great to support this. Should also be not too hard to implement, we just have to strip the unit from the ticks, just like we to for e.g. the lims:

ustripattribute!(attr, axislims, u)

You want to give it a stab? A PR would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants