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

[BUG][PGFPlotsX][Unitful] setting axis labels duplicates units #4730

Closed
xwjqv opened this issue Apr 26, 2023 · 5 comments · Fixed by #4747
Closed

[BUG][PGFPlotsX][Unitful] setting axis labels duplicates units #4730

xwjqv opened this issue Apr 26, 2023 · 5 comments · Fixed by #4747
Labels
bug help wanted PGFPlotsX UnitfulExt recipes for Unitful quantities

Comments

@xwjqv
Copy link
Contributor

xwjqv commented Apr 26, 2023

When setting axis labels while using units and the PGFPlotsX backend,
the units appear twice in the label.

This probably happens because of the changes in #4723.
The units are also incorrectly italicized (maybe use UnitfulLatexify.jl for it)

Details

Example

using Plots, Unitful
pgfplotsx()
plot([1u"s",2u"s"],[1u"m",2u"m"],xlabel="t",ylabel="r")

svg-image

crashing example

This has probably the same cause as #4722

using Plots, Unitful
pgfplotsx()
plot([1u"s",2u"s"],[1u"m/s^2",2u"m/s^2"],xlabel="t", ylabel="a")

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: master
Backend version (]st -m <backend(s)>): PGFPlotsX v1.5.3
Output of versioninfo():

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 1700 Eight-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, znver1)
  Threads: 8 on 16 virtual cores
Environment:
  JULIA_REVISE_WORKER_ONLY = 1
@xwjqv xwjqv added the bug label Apr 26, 2023
@BeastyBlacksmith BeastyBlacksmith added UnitfulExt recipes for Unitful quantities PGFPlotsX labels Apr 26, 2023
@BeastyBlacksmith
Copy link
Member

CC: @t-bltg

@t-bltg
Copy link
Member

t-bltg commented Apr 27, 2023

Hum sorry for this.

Unitful was written for GR and we never tested it on PGFPlotsX (neither in regression tests). So everything is left to be correctly implemented here.

There are choice to be made. I'd say that the units should be in math mode for handling braces/parens (hence rendered slightly italicized). But it's to be discussed.

Contributions welcome 🙂.

Ping @gustaphe for discussion.

@gustaphe
Copy link
Collaborator

UnitfulLatexify has a recipe for (label, unit) tuples, so plot(rand(5)u"m", rand(5)u"s"; unitformat=latexify, xguide="x", yguide="t") looks good in GR. I have not tried it in pgfplotsx but perhaps that's the solution here? One of these days I may find some time to look at it.

@gustaphe
Copy link
Collaborator

I can't find where, but somewhere the UnitString guide is transformed into a String when using pgfplotsx.

@gustaphe
Copy link
Collaborator

Nvm, found it in the fix to the linked issue.

The overloading of the guide attribute is a bit of a problem: UnitfulExt uses it to store information about the axis units. It's clever, but not necessarily in the good way.
Either pgfplotsx should change to storing the UnitfulString and transforming it at the printing point, or we should think of a less cludge way to keep track of axis units. I have no good suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted PGFPlotsX UnitfulExt recipes for Unitful quantities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants