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] can't display dollar currency symbol as y-axis label #3991

Closed
mdkeehan opened this issue Dec 9, 2021 · 8 comments
Closed

[BUG] can't display dollar currency symbol as y-axis label #3991

mdkeehan opened this issue Dec 9, 2021 · 8 comments
Labels

Comments

@mdkeehan
Copy link
Contributor

mdkeehan commented Dec 9, 2021

Details

When I run the following code:

using Plots
plot(rand(3,5),ylabel="profits \$")
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error

while the euro unicode symbol will work beautifully

plot(rand(3,5),ylabel="profits €")

Backends

This bug occurs on ( insert x below )

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

Versions

Plots.jl version:
Plots v1.25.1

Output of versioninfo():
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

@mdkeehan mdkeehan added the bug label Dec 9, 2021
@mdkeehan
Copy link
Contributor Author

mdkeehan commented Dec 9, 2021

Some more experiments:

julia> plot(rand(3,5),ylabel=raw"profits $")
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error

julia> plot(rand(3,5),ylabel=raw"profits $")
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error
ERROR: syntax error

julia> GR.plot(rand(3,5),ylabel=raw"profits $")
ERROR: syntax error
ERROR: syntax error

julia> GR.plot(rand(3,5),ylabel="profits \$")
ERROR: syntax error
ERROR: syntax error

julia> GR.plot(rand(3,5),ylabel=raw"profits $")
ERROR: syntax error
ERROR: syntax error

A work around was too embed unusual unicodes characters that look like dollars but I then run into fonts supporting glyph problems.
It looks like Plots "interpolates" 5 times while calling GR directly interpolates only twice.

@mdkeehan
Copy link
Contributor Author

mdkeehan commented Dec 9, 2021

plottlyjs() works correctly.

julia> plotlyjs()
Plots.PlotlyJSBackend()

julia> plot(rand(3,5),ylab="profits \$")

julia> gr()
Plots.GRBackend()

@BeastyBlacksmith
Copy link
Member

@jheinen: Anything we can do about it?

@jheinen
Copy link
Member

jheinen commented Dec 10, 2021

Right now (with the GR development branch), the only workaround is to use plot(rand(3,5),ylab="profits \$\$"). I have to admit, that looks odd. I (have to) think of something better.

@ShuhuaGao
Copy link

When some more words follow \$, then no error is reported. However, the dollar symbol is not rendered and disappears.

using Plots
plot(rand(3,5),ylabel="profits \$/kWh", size=(500, 200))

temp

In the above, it seems that "kWh" was treated as in an equation environment.

As @jheinen mentioned, plot(rand(3,5),ylabel="profits \$\$/kWh", size=(500, 200)) works well.

@jheinen
Copy link
Member

jheinen commented Nov 16, 2022

This problem is fixed in the GR development tree. We will tag a new GR release ASAP.

@t-bltg
Copy link
Member

t-bltg commented Nov 27, 2022

Fixed by sciapp/gr@f37dfaa.

@t-bltg t-bltg closed this as completed Nov 27, 2022
@matthewelmer
Copy link

matthewelmer commented Dec 6, 2023

So how do I put dollar signs in axis labels now that this is "fixed"? As of now, xlabel=raw"$t$ (seconds)" produces some LaTeX-ified t followed by " (seconds)". I want a literal "$t$ (seconds)" as plaintext so that I can save the figure as svg with fontfamily="" so that I can typeset the axis labels when I include the svg in my LaTeX document.

Doing xlabel=L"\$t\$ (seconds)" makes it puke

latex: failed to create a dvi file
latex: failed to create a dvi file
latex: failed to create a dvi file
latex: failed to create a dvi file
latex: failed to create a dvi file

into stdout and puts a weird backslash where the first dollar sign should be

Update: I came up with a hack to get what I want. Everywhere you want a literal dollar sign, put two. Then,

tmppath, tmpio = mktemp()
open("filename.svg") do file
    for line in eachline(file, keep=true)
        write(tmpio, replace(line, raw"$$" => raw"$"))
    end
end
close(tmpio)
mv(tmppath, "filename.svg", force=true)

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

No branches or pull requests

6 participants