kupiqu/fig2svg

Text alignment is incorrect

Closed this issue · 15 comments

I am importing the figure from MATLAB and the text alignment is incorrect. This is how it looks like in InkScape:
screen shot 2018-11-03 at 12 25 58

And in the file viewer, it is indeed a bit higher than it is supposed to be, for example:

screen shot 2018-11-03 at 12 28 56

I have to adjust the text to bring it lower when importing to pdf_tex. But what causes the problem?

Really no idea with just a screenshot (which is useful to see what the result is but not the cause), or in other words, if I knew this would have been probably fixed already.

So, please tell me your matlab version and give the most minimalistic code snippet you can get that reproduces the issue in your system for me to try reproducing and debugging the issue in mine.

Yes sorry was actually doing that but hit posted before actually finishing it. It can be as simple as this:

x=[1:10] y=[1:10] plot(x, y) xlabel('some text that is not aligned') xticks([1 5 10]) xticklabels({'some'; 'text'; 'arent aligned'}) plot2svg 'Figures/test.svg'

It will be exaggerated if you set the font size:

set(gca, 'FontSize', 13,'LineWidth', 2, 'FontName', 'Roboto');

I am using 2018b but I had this problem since 2016b

On MATLAB:
screen shot 2018-11-03 at 12 46 32

On viewer:
screen shot 2018-11-03 at 12 46 44

In inkscape:
screen shot 2018-11-03 at 12 48 31

Thanks. I'll take a look... (text alignment is very tricky though, but it may be room for improvement).

Sorry, I cannot reproduce. It may be the problem is in your viewer. What viewer is it?
I tested this exact code:

x=[1:10];
y=[1:10];
plot(x, y)
xlabel('some text that is not aligned')
xticks([1 5 10])
xticklabels({'some'; 'text'; 'aren''t aligned'})
set(gca, 'FontSize', 13,'LineWidth', 2, 'FontName', 'Roboto')
plot2svg 'test.svg';

Matlab 2018b:

image

Chromium:

image

Inkscape:

image

Does the alignment in inkscape works fine for you too? Because I have problem in inkscape, i dont really care about the viewer. I mean if you select the texts, is it selecting the text, or selecting the space above text? and which inkscape version are you using?

You'll have to highlight the text in inkscape for me to know. For example, here's using plot2svg, the node (small square) is above text and the highlighted part are above the text:

screen shot 2018-11-03 at 14 12 57

here's using MATLAB save as svg:

screen shot 2018-11-03 at 14 13 22

My MATLAB's default vertical alignment is 'Top' for xlabel and any text I put. And for some reason, plot2svg is not converting the position correctly

Another problem is: when I hit enter on the text (in inkscape) to make it double like, the text is divided into two boxes?

These problems do not exist when I tried using the old plot2svg. however, i do need to use the scatter function. much appreciated for your help!

I see. That might be as it uses baseline shifts for alignment. Will take a look when I get back to my computer...

I can confirm this shift in the baseline. Unfortunately, this comes from how text is currently allocated in plot2svg. It's certainly not optimal, but didn't find a better way. Other options I tested created a visual offset, which is far from trivial to compensate for (different font sizes, axes locations, 2d vs 3d plots etc.).

So I will leave this issue open as a low priority bug for now. Feel free to submit a pull request if you happen to find a better solution.

I wonder if there's any explanation why the previous version of plot2svg works and if there's a simple workaround for this? it seems to happen in only xtick and xticklabel

I wonder if there's any explanation why the previous version of plot2svg works and if there's a simple workaround for this? it seems to happen in only xtick and xticklabel

The previous version manually compensated for the offset, but I found it to be suboptimal under certain circumstances. This new version seemed to work better in general, although I wasn't aware of this current issue...

fixed with commit d8a4444

Current implementation seems much better, @sharahamo please give it a try.