-
-
Notifications
You must be signed in to change notification settings - Fork 365
Add unit
axis attribute (for v2)
#5095
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
base: v2
Are you sure you want to change the base?
Conversation
@gustaphe should probably weigh in on this, I suspect |
I am generally in favor, have not checked the details yet. I can't even run the code, something about The elegant way to do this would be to have axis properties I have a resting project of baking UnitfulLatexify into Unitful, which would solve the loading bug. Just need a bit of vacation to work on it. |
That's a two-line fix in #5094 😅, I left that as a separate PR because it seemed like it would need less discussion.
The current current depends whether a plot call happened last, so I need to change at least a bit. Possibly I could split into two PRs, one with a less-elegant fix for 1.x and a better one for 2.0, depending how easy it is for me to figure this out. |
With the most recent commit, this implements the more "elegant" solution of waiting until render time to generate the guide, at which point unit and unit format are both known. If no units are supplied, then it ignores If this looks too invasive, I can walk it back and look at other solutions. Without something like this, though, it's hard to update the Plots.jl/PlotsBase/src/Axes.jl Lines 324 to 334 in 4d289ba
if haskey(kw, :guide) || haskey(kw, :unit) || haskey(kw, :unitformat)
plotattributes[:guide] = ...
end but that felt more awkward to me, especially since there is already a function |
I believe all the tests are passing now. To make that so, I had to do a couple things that may merit discussion.
|
Failing CI notwithstanding, I like this a lot. I think it would be good to get the opinion of someone else (github suggests @t-bltg), because I have a quite Unitful focused view and this might in theory make handling axis guides slightly more cumbersome for someone who does not.
|
I also think it's a good idea to implement |
Description
In an attempt to fix #4750 and #4822 , following the suggestion in #4822 (comment) to move units from the label (so a string) to an actual axis attribute.
This currently generates correct plots and solves the above issues, but the axis label behavior is probably still a little wonky--e.g., units may get added to an axis label after the user sets the label not to have them. That would be an important part of making this work properly, I think, so I'll mark this "draft" for now, but I would welcome suggestions about how that should behave: for example, should
unitformat
always be used, and users have to setunitformat
to:nothing
if they don't want the units printed? Or perhaps respect theProtectedString
API? In the past I found theProtectedString
to be a little annoying but haven't thought yet about how it will interact.The current code is almost certainly not as elegant as it should be, and once I have an idea of desired label behavior there will probably be some pieces leftover that can be deleted.
MWE for testing
Attribution
(assuming UnitfulExt: Check if PGFPlotsX is available, then check if it's the current backend #5094 merges)
Things to consider