[matlab2tikz] YTick changes when removing YTickLabel

Hello,
I use boxplot to produce different graphs. I arrange those graphs next to each other in LaTex. I set YLim for all equal. It looks like this:
Everything is fine, except that I want to save space and therefore want to delete YTickLabel without any other changes. Then the YTicks change as well! It looks like this:
I tried to avoid the change of YTick on YTickLabel remove adding the following lines, which read out YTick before removing YTickLabel and set it again after removing YTickLabel. But it did not work! Why? Is there any possibility to make YTick NOT CHANGE when removing YTickLabel?
Thanks in advance for your help!!
using Matlab R2015a on Windows
____________________
Solution: matlab2tikz added a line ytick={....} to the code which modified axes. Adding uncomment to this line in the output file via script solved the problem in a work-around.
____________________
Kind regards Tobias

6 Comments

Give us a pasted text demo code (short as possible) that illustrates the issue that can paste in and use instead of images; nothing anybody can do with them other than look.
It would seem simply clearing 'yticklabel' shouldn't affect any of the tick positions themselves, agreed. I don't have time at the moment to try to duplicate as have meeting in few minutes so help us help you by giving the example in code...
Actually it can affect the tick positions.
We're just guessing without seeing the code, but the tickpicker chooses tick values based on the amount of room it has, and the length of the tick labels affects the amount of room it has. This means that the interaction between the two can be surprising and non-linear.
I would think that your best bet when you don't want the values to change would be to set TickValuesMode to manual.
It also sounds like you want the limits to stay in synch, is that correct? If so, you might want to consider using linkaxes:
ax = [subplot(1,3,1),subplot(1,3,2),subplot(1,3,3)];
set(ax(2:3),'YTickLabels',{})
set(ax,'YGrid','on')
linkaxes(ax,'y')
I could see the position affecting the X axis when removing Y tick labels as there's subsequently more room but don't see why it should affect spacing on the same axis. 'Spearminting here some didn't cause the symptom.
I agree linkaxes may help 'cuz it'll keep ylim the same.
I was mightily confused by OP's reference to LaTex and not seeing the axes creation. My guess was he was putting together three separate figures externally rather than using subplot (which is where I'd've started, too, and I suspect there it will behave as he would expect...but, we need to see a piece of code from OP that generates the issue he's having to be certain, agreed...
The X & Y aren't actually independent in MATLAB's tickpicker, and the relationship between the two can be rather surprising.
Hello Mike,
thanks for the answer! It seems to work for default matlab plot even without the explicit linkaxes! Unfortunatley, this did not solve the problem for my plotting library matlab2tikz.
I figured out, that matlab2tikz library adds a line ytick={.....} in my case which modifies yticks. When I open the output file and comment it out, it perfectly works. So I just added this to my script as work-around:
matlab2tikz(filename,'width','\figW','height','\figH','showInfo',false);
fid = fopen(filename,'r');
f=fread(fid,'*char')';
fclose(fid);
f = regexprep(f,'ytick={','%ytick={');
fid = fopen(filename,'w');
fprintf(fid,'%s',f);
fclose(fid);
Thank you guys! How can I mark the question as solved?
@ruekelt -- Move your comment above to Answer; since we didn't have an actual answer there's no way to mark comments as having lead to the result...
@ Mike -- it may be there's some interaction but I don't recall ever having removing tick labels on a given axis doing anything to the tick values or limits. And, here, as suspected, there was a hidden explicit xtick change...but, if something bizzaro does sometime show up I'll keep your warning in mind.

Sign in to comment.

Answers (0)

Asked:

on 5 Apr 2016

Commented:

dpb
on 6 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!