Closed moroses closed 3 years ago
@moroses can you provide a screenshot of what this looks like before and after?
Hi @briochemc , Sure, the left panel is the before and the right panel is the after
Are you using LaTeXStrings? Can you share a MWE?
I am not using LaTeXString in this example. I will work on a MWE shortly.
Merging #40 (444fbd6) into master (e80cb4a) will not change coverage. The diff coverage is
100.00%
.
@@ Coverage Diff @@
## master #40 +/- ##
=======================================
Coverage 83.11% 83.11%
=======================================
Files 1 1
Lines 77 77
=======================================
Hits 64 64
Misses 13 13
Impacted Files | Coverage Δ | |
---|---|---|
src/UnitfulRecipes.jl | 83.11% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 6d94473...444fbd6. Read the comment docs.
using Unitful, UnitfulRecipes, Plots
gr() # just to make sure
x = 1.:10
x *= u"s"
y = x .^ 2
plot(x,y, ylabel="\\sigma", guidefontsize=font("Times"))
OK, so I don't have any issues with your MWE with the current master. Note, however, that I'm on a mac, and that Unitful.jl prints exponents as Unicode on mac (since https://github.com/PainterQubits/Unitful.jl/pull/297). That being said, unless you have fractional exponents (something like s^{1//2}
), you can probably use the workaround suggested in https://github.com/PainterQubits/Unitful.jl/pull/297, which is to set the UNITFUL_FANCY_EXPONENTS
environment variable. Could you try and rerun your MWE (or your original plot) on the current UnitfulRecipes.jl release, but setting
ENV["UNITFUL_FANCY_EXPONENTS"] = true # I think that's how it's supposed to work
before you run it?
Otherwise, AFAIU, the issue you are facing is that Plots silently uses LaTeXStrings.jl when you ask it to label something with "\\sigma"
instead of using the Unicode "σ"
. So another workaround for you is to restrict yourself to Unicode labels (e.g., maybe use "|σ_z(m)|²"
as your label in your original plot (no Unicode for subscript Z
AFAIK)).
Could you try these two workarounds (and maybe even try to combine them) to see if they work on your machine?
Finally, maybe a more complete solution would be to think about adding LatexStrings.jl and/or UnitfulLatexify to the deps here?
Disclaimer that I use UnitfulRecipes to plot things quickly with units during exploratory research, and I'd use Makie or something else to spend time on complicated labels. (I'm also not a big fan of LaTeX in figures and tend to prefer Unicode alternatives.) But this is all personal preference that I understand is not shared by everyone! 😄
Thanks @moroses for the PR. Like @briochemc I think it is worth to also explore alternative solutions. No matter how this is fixed in the end, it might be worth documenting it. For instance by adding plots here.
@moroses Did you end up trying the workarounds with ENV["UNITFUL_FANCY_EXPONENTS"]
and/or ylabel="σ"
?
Hi, Actually, I kinda left it alone. I had to format the units with square brackets instead of parenthesis and use italics font. So I ended up using a ProtectedString for the label.
OK, no worries! FWIW, you may also want to use the pgfplotsx()
backend too :)
When the units have powers, you need to escape the powers with {...} in order to have the following text remain in normal script.