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

Plots, GR backend & math in titles #512

Open
B-LIE opened this issue Feb 27, 2023 · 9 comments
Open

Plots, GR backend & math in titles #512

B-LIE opened this issue Feb 27, 2023 · 9 comments

Comments

@B-LIE
Copy link

B-LIE commented Feb 27, 2023

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:
image|356x64

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.

@B-LIE
Copy link
Author

B-LIE commented Feb 27, 2023

Hm -- the same problem seems to be present in labels:
image

@jheinen
Copy link
Owner

jheinen commented Feb 27, 2023

Could you please provide a MWE? Thanks.

@B-LIE
Copy link
Author

B-LIE commented Feb 27, 2023

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
image

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...
image
The math appears as slightly below the baseline of the ylabel -- and somewhat smaller. Same for xlabel.
image

I've seen more marked differences in baseline of text and math in other examples.

@jheinen
Copy link
Owner

jheinen commented Feb 27, 2023

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()

@B-LIE
Copy link
Author

B-LIE commented Feb 27, 2023 via email

@B-LIE
Copy link
Author

B-LIE commented Feb 28, 2023

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:

image

@jheinen
Copy link
Owner

jheinen commented Feb 28, 2023

You can run these commands only in a console window.

@B-LIE
Copy link
Author

B-LIE commented Feb 28, 2023

You can run these commands only in a console window.

OK -- then I get the following:
image

@jheinen
Copy link
Owner

jheinen commented Mar 1, 2023

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 ...

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

No branches or pull requests

2 participants