Hello. I'm trying to add a text to the plot with the following code ```golang fonts := font.NewCache(liberation.Collection()) plot.DefaultTextHandler = text.Latex{ Fonts: fonts, } labels, err := plotter.NewLabels(plotter.XYLabels{ XYs: []plotter.XY{ {X: 0, Y: 0}, }, Labels: []string{ "Money % spent today: 10", }, }) if err != nil { log.Fatalf("could not create labels: %+v", err) } labels.TextStyle[0].Font.Size = 24 labels.TextStyle[0].Color = color.RGBA{B: 255, A: 255} labels.TextStyle[0].XAlign = draw.XCenter labels.TextStyle[0].YAlign = draw.YCenter p.Add(labels) ``` code was taken from the example https://github.com/gonum/plot/blob/master/text/latex_example_test.go But I get nothing on the plot except Money. Like % sign cuts everything else. Could anyone give a hint on how to add a % sign to a string?
Activity
kortschak commentedon Aug 16, 2025
This is a LaTeX issue.
%is the LaTeX comment mark. Try\\%.jokaorgua commentedon Aug 16, 2025
thanks for the quick response. tried \%, %%, \u0025 - does not work.
maybe there is another way to add a multi-line text box to a plot?
kortschak commentedon Aug 16, 2025
Did you try
\\%?jokaorgua commentedon Aug 16, 2025
yes, github escaped :) tried
\\%%%\u0025kortschak commentedon Aug 16, 2025
I just had a look and it seems the length of the text is the issue. @sbinet will likely have a better understanding of what is going on here.
kortschak commentedon Aug 16, 2025
With the following change, the plot renders no text. One less, and text is present.
sbinet commentedon Aug 16, 2025
sbinet commentedon Sep 2, 2025
apologies for the belated answer.
with the following:
(ie: use backticks and
\%in math-mode.)I got:
kortschak commentedon Sep 2, 2025
That explains the percent sign, but the longer text still causes all the text to be lost.
sbinet commentedon Sep 2, 2025
this is probably unrelated to any LaTeX issue:
one more
3and one gets:I'd say this comes from a too small Y-axis ?
adding a
"5"at{X: +0.5, Y: +100}(as the last label), one gets:if one adds it as the first label, one gets:
to sum up, I suspect there are possibly 2 bugs:
plotter.NewLabels(b/c of the order of theXYLabelsmatters)plot.Axis