Which backend are you using for Plots?
If you haven’t selected it then you’re using the default one (GR). In my experience, the solution given in the answer above your post should work, then… something like "\$\\mathrm{Unit is} 10^3\$"
Maybe you could try PGFPlots?
using Plots; pgfplots()
using LaTeXStrings
An example:
plot(..., ..., label=L"...", yaxis=:log, lw=1, color=1, line=:dot, xlabel=L"k", ylabel=L"\|r_k\|", legend=:best)
Hello Guys,
I am in Juno and under Linux. I could not get aplha on my PyPlot graphs, and the following worked for me after some trial runs, e.g.:
using Plots, LaTeXStrings
plot!(xdata, ydata, label = "\\alpha")
Hope this will help somebody…
Btw, i realized that if you want to combine greek and other characters with a text, it gets a bit trickier…
I could solve it through this hack (funny part, no using LaTeXStrings is needed), e.g.:
ylabel!("Permeability in z-direction"*"\\mu"*"m")
Works for titles, data and axes labels.
Can I use \frac? in a title?
using Plots
using LaTeXStrings
f(x)=1/sqrt(x+x^2)
plot(f,title=L "f(x) = \frac {1}{x+x^{2}}"
You can, but you need to make sure you construct the Latex string correctly - in the above you have a space between the L
and the start of the string "
which won’t work, you need L"f(x)..."
using Plots
using LaTeXStrings
plot(0:2,0:2, xlab = L"x^2", xticks = ([0,1,2],[L"0", L"1", L"2"]))
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
'latex' is not recognized as an internal or external command,
operable program or batch file.
latex: failed to create a dvi file
Julia>versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, ivybridge)
Just a quick note of what works for me:
plot(xlabel="axis label \$\\alpha^3_{AB}\$")
I’m using PyPlot in Jupyter Notebook on Windows, and Julia Version 1.4.1.
I’ve tried a lot of combinations of Latexstrings, double backslashes, dollar signs, etc., and only found this by accident. In the end, the syntax that seems to work is just putting one additional backslash in front of most latex commands (including the math mode dollar signs, but not subscripts and superscripts for example).
You are right, they change at times. I had to find the combination that worked for me, but months later then i run the same script - the results were different…
This is a bit disappointing indeed, i hope plotting packages will get stable and will produce consistent results in the nearest future.
I am trying to use L"..."
to add a label to a plot using Plots
.
I try to include both normal text and a symbol like:
L"coordinate, $x$"
However, it does not do the latex formatting. What could be the issue?
I know that as a workaround I can do
L"\textrm{coordinate, } x"
and it works, but I was wondering what is the problem with the former way.
I think what happens here is that the “L” terms calls symbol $ automatically, meaning that L"coordinate, $x$
is similar to "$coordinate, $x$$
. Just try calling L"something"
and you can see it returns L"$something$
.
No, that’s not what it does,
julia> String(L"coordinate, $x$")
"coordinate, \$x\$"
LaTeXStrings.jl
knows to not add surrounding dollar signs if there are dollar signs in the string.
The problem @roi.holtzman is having is that the backend doesn’t actually automatically show LaTeXString
s as LaTeX, but rather looks for those dollar signs. And it doesn’t know what to do with mixed strings (GR
doesn’t actually call a LaTeX engine but a bespoke approximation of one). To GR
there is no difference between L"x"
and "\$x\$"
, and between L"coordinate, $x$"
and "coordinate, \$x\$"
. The latter two are not detected as math.
textrm
is the solution to this.
This is an old thread, but which has no solution marked. Probably the solution to the original post is this:
Just to keep the forum here somewhat up to date…
I think now the package is called LaTeXStrings
(see Github).