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

Text from legendflex has vertical position offset #1118

Open
SchapplM opened this issue Jan 19, 2023 · 3 comments
Open

Text from legendflex has vertical position offset #1118

SchapplM opened this issue Jan 19, 2023 · 3 comments

Comments

@SchapplM
Copy link

I am currently trying to save a figure with multiple legends created by legendflex. There is a minimal example in my fork of the repository.
With matlab2tikz the vertical position of the legend text has an offset which disturbs the figure and in other cases makes the text leave the box.
result with original version
If I manually add -6 to the text vertical position, then the position looks ok:
result with patch
In Matlab and in PDF export, the spacing looks ok:
Matlab window

Therefore, the error should be in the way which matlab2tikz handles the text.
The cutting of the text to the right can be solved by the padding command in legendflex, but also is annoying.

@egeerardyn
Copy link
Member

egeerardyn commented Jan 19, 2023

I agree with you that it's inconvenient to use.

However, I would disagree with your evaluation of where the error is: it is not in matlab2tikz, but rather in legendflex.

A quick read of it's source code indicates that legendflex is looking at the extent of the text boxes to size the secondary legend.
Also have a look at the LaTeX issue mentioned on the legendflex docs, it is very much related.

Intuitively: on the MATLAB rendering it is looking at the text, checking: this textbox is 50 px wide, so the whole box should be e.g. 60 px wide (50px + padding) such that the box is bigger than the text. However, on the matlab2tikz and LaTeX side, we only see a text box containing some text and a rectangle that is 60 px wide. Matlab2tikz has no more semantic information that the box should be bigger than a certain string of text, so it just translates that into the equivalent pgfplots code taking into account whatever information it has on hand.

So unfortunately, there is nothing immediate that can be done in matlab2tikz to mitigate this; as the issue seems to stem from how the extents of those objects get set in legendflex. So I would suggest to use the workarounds mentioned on the legendflex documation.

@egeerardyn
Copy link
Member

Woops, I didn't fully read your post that it's mainly about the vertical alignment.

However, the source is the same:
in MATLAB the extent of the text box is computed as some values [X, Y, width, height] in pixels (see the legendflex code), those explicit coordinates are translated by matlab2tikz to equivalent pgfplots code, but there we no longer have the guarantee that that extent is conveying the same semantic info (width should be large enough to contain the text, Y position and height are such that it aligns to the middle of the symbol) as in MATLAB; since we do not have that semantic info anymore when we convert the figure.

@SchapplM
Copy link
Author

Thanks for the explanation. I will then use my workaround and the tips from the legendflex docu you mentioned.

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

No branches or pull requests

2 participants