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] Log scale axis labels not brace-wrapped in PGFPlotsX #4676

Closed
ivan-boikov opened this issue Mar 2, 2023 · 3 comments · Fixed by #4680
Closed

[BUG] Log scale axis labels not brace-wrapped in PGFPlotsX #4676

ivan-boikov opened this issue Mar 2, 2023 · 3 comments · Fixed by #4680

Comments

@ivan-boikov
Copy link
Contributor

ivan-boikov commented Mar 2, 2023

Details

Log scale axis labels with a power of two symbols or more is broken

using Plots
pgfplotsx()
PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX) # doubt it's relevant, but just in case - I use it
plot(
    plot([1e-5, 1e10]; title="Automatic labels",
        yticks=[1e-5, 1e0, 1e10]),
    plot([1e-5, 1e10]; title="Manual labels",
        yticks=([1e-5, 1e0, 1e10], ["\$10^{-5}\$", "\$10^{0}\$", "\$10^{10}\$"])),
    legend=:none, yscale=:log10
)

image

Looking at the generated .tex

savefig("plot.tex")
open("plot.tex") do f
    for line in eachline(f)
        i0 = findfirst("yticklabels=", line)
        i1 = findfirst("ytick=", line)
        if !isnothing(i0)
            println(line[i0[1]:i1[1]-3])
        end
    end
end
yticklabels={{$10^-5$,$10^0$,$10^10$}}
yticklabels={{$10^{-5}$,$10^{0}$,$10^{10}$}}

we see that the power is not wrapped automatically.
The behavior changed between v1.38.1 and v1.38.2, so I suspect #4618 was almost there - the tests only covered single-digit powers.

Looks like it can be fixed here

Dict{Symbol,Function}(:log10 => x -> "10^$x", :log2 => x -> "2^$x", :ln => x -> "e^$x")

by changing to

Dict{Symbol,Function}(:log10 => x -> "10^{$x}", :log2 => x -> "2^{$x}", :ln => x -> "e^{$x}")

though it's a low-level function and I am not confident enough to open a PR.

Backends

This bug occurs on ( insert x below )

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

Versions

Plots.jl version: v1.38.6
Backend version (]st -m <backend(s)>):

[28b8d3ca] GR v0.71.7
[8314cec4] PGFPlotsX v1.5.3
[b8865327] UnicodePlots v3.4.0

Output of versioninfo():

Julia Version 1.8.1
Commit afb6c60d69a (2022-09-06 15:09 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × AMD Ryzen 5 3600 6-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, znver2)
  Threads: 1 on 12 virtual cores
@ivan-boikov ivan-boikov added the bug label Mar 2, 2023
@ivan-boikov
Copy link
Contributor Author

Actually, scratch that "fix", it changes font in GR to computer modern and who knows what mayhem it causes in other backends

@ivan-boikov
Copy link
Contributor Author

Looking at it again, I think this would be a better fix: add

labelfunc(scale::Symbol, backend::PGFPlotsXBackend) = labelfunc_tex(scale)

to src/backends/pgfplotsx.jl

@t-bltg
Copy link
Member

t-bltg commented Mar 3, 2023

Ping @daschw for #4618.

though it's a low-level function and I am not confident enough to open a PR.

Nah, you should open a PR with added tests, it's the best way to get your issue fixed.
Anyone can start contributing (tips here: https://docs.juliaplots.org/stable/contributing) !

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

Successfully merging a pull request may close this issue.

2 participants