GR.jl
GR.jl copied to clipboard
Plots, GR backend & math in titles
Seems like there is a slight problem with the GR back-end of Plots when it comes to math in titles. Here is an example:
Notice that the math does not align well with the non-math text (e.g., the $N$ at the end is too low; the same is true of the other math). Also observe that here, I inserted word "and" in the math part; if I didn't do that, it looked considerably worse.
Apart from this, I'm very happy with the GR package (OK -- there may be other minor issues). I stopped using the PyPlot backend some time ago -- essentially because (i) it stopped working properly, and (ii) GR gave crisper lines, and overall nicer looking plots.
Hm -- the same problem seems to be present in labels:
Could you please provide a MWE? Thanks.
I use Julia 1.8.3 on Windows 11, an HP laptop with Full HD resolution.
using Plots
using LaTeXStrings
plot(sin, label=L"this is $f(x)$")
plot!(title=L"$\sin$ as a function of $x$")
plot!(xlabel=L"position $x$")
plot!(ylabel=L"mapping $\sin(x)$")
I saved the plot as svg
:
savefig("C:/Users/.../OneDrive/Desktop/test.svg")
I then drag the svg-file into a blank Word document, where I can zoom to see the figure in detail.
Parts of plot
In the title line, $\sin$ is somewhat below the baseline of the text; $x$ is somewhat above.
I'd say that $f(x)$ is the slightest below the base line of the text in the legend/label.
The ylabel...
The math appears as slightly below the baseline of the ylabel -- and somewhat smaller. Same for xlabel.
I've seen more marked differences in baseline of text and math in other examples.
Could you please execute the following commands and provide a screenshot?
using GR
using LaTeXStrings
text(0.1, 0.9, L"this is $f(x)$")
text(0.1, 0.8, L"$\sin$ as a function of $x$")
text(0.1, 0.7, L"position $x$")
text(0.1, 0.6, L"mapping $\sin(x)$")
settextfontprec(232, 3)
text(0.1, 0.4, L"this is $f(x)$")
text(0.1, 0.3, L"$\sin$ as a function of $x$")
text(0.1, 0.2, L"position $x$")
text(0.1, 0.1, L"mapping $\sin(x)$")
updatews()
Will do when I'm back at computer.
Sent from Outlook for Androidhttps://aka.ms/AAb9ysg
From: Josef Heinen @.> Sent: Monday, February 27, 2023 7:01:28 PM To: jheinen/GR.jl @.> Cc: Bernt Lie @.>; Author @.> Subject: Re: [jheinen/GR.jl] Plots, GR backend & math in titles (Issue #512)
Could you please execute the following commands and provide a screenshot?
using GR using LaTeXStrings
text(0.1, 0.9, L"this is $f(x)$") text(0.1, 0.8, L"$\sin$ as a function of $x$") text(0.1, 0.7, L"position $x$") text(0.1, 0.6, L"mapping $\sin(x)$") settextfontprec(232, 3)
text(0.1, 0.4, L"this is $f(x)$") text(0.1, 0.3, L"$\sin$ as a function of $x$") text(0.1, 0.2, L"position $x$") text(0.1, 0.1, L"mapping $\sin(x)$")
updatews()
— Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjheinen%2FGR.jl%2Fissues%2F512%23issuecomment-1446796574&data=05%7C01%7C%7C512e1c59067042ea4f4208db18eca6c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638131176910587967%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=VADlLo17gQe7sA2Z9Xyowfy6UTOyCdWUy8pB7xcU3xM%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAM5VM7ZH4SGXJSTJJEG7EM3WZTTXRANCNFSM6AAAAAAVJEGWHQ&data=05%7C01%7C%7C512e1c59067042ea4f4208db18eca6c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638131176910587967%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mrpnj2xhL98LW2DQAKu1VrlpN7H3kZcEm2O%2BJsgmHUc%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.***>
I restarted the Jupyter notebook (in VSCode), and ran exactly the code you suggested above.
The code runs without problems, but there is not output/response on the screen except that it runs the code:

You can run these commands only in a console window.
You can run these commands only in a console window.
OK -- then I get the following:
I have no explanation yet why the alignment depends so much on the font - with plain GR text (and without embedded LaTeX strings) the positioning in GR is pixel-precise. We will have a closer look at this ...