Matlab ylabel cutoff using plotyy function
Asked Answered
L

1

6

As seen in an included screenshot, the EPS output of matlab is cutting of the label on the right hand side Y axis.

I am using the plotyy function, and printing to eps with: print(f1,'-depsc2' ,'figure1.eps');

I have tried changing the paperposition property, as well as the papersize property, and these seem to keep scaling with the other at each adjustment, and therefore i can never get the paper size to increase on the the right.

I have set paperpositionmode to manual.

Does anyone have any ideas?

I have created some sample code that is self sufficient and replicates the problem. The problem is created when increasing the tick and font sizes. However this is essential for my situation.

close all;

% example data:
x = 0:0.01:4;
y1 = 5*sin(2*pi*x+0.1) + 20;
y2 = 0.09*sin(2*pi*x);

tickfontsize = 18;
labelfontsize = 20;

% begin figure:
f1 = figure(1);
[ax, h1, h2 ] =  plotyy(x,y1,x,y2)

% axis labels and font size:
set(get(ax(2),'Ylabel'),'String','Test1') ;
set(get(ax(1),'Ylabel'),'String','test2') ;
set(get(ax(1),'Ylabel'),'FontSize',labelfontsize) ;
set(get(ax(2),'Ylabel'),'FontSize',labelfontsize) ;

% left hand side ticks:
set(ax(1),'YLim',[6 10]);
set(ax(1),'YTick',[6:1:10]);
set(ax(1),'FontSize',tickfontsize);

% right hand side ticks:
set(ax(2),'YLim',[-0.13 0.14]);
set(ax(2),'YTick',[-0.1:0.05:0.1]);
set(ax(2),'FontSize',tickfontsize);

%print figure to eps:
print(f1,'-depsc2', './simpleoutput.eps');

Screenshot of EPS output

Literally answered 24/9, 2013 at 14:18 Comment(3)
Can you provide a minimal working example that regenerates your problem, please? With a quick-and-dirty plotyy and your print-command I could not get a cut-off label.Sinful
@Sinful Thanks for your comment, I have included some code that will replicate the problem for you.Literally
Someone asked a similar question on Mathworks Newsgroup three years ago:link. It seems that there was no easy automatic solution for this problem and you have to do as in Luis' answer.Domel
M
6

Change axes position to make them narrower:

set(ax(1),'Position', [0.13 0.11 0.775-.08 0.815]);
set(ax(2),'Position', [0.13 0.11 0.775-.08 0.815]);
% Original position was [0.13 0.11 0.775 0.815]
% Applied change in width: "-.08". Choose as desired

If you need to keep axes ratio, you should also modify height (fourth number).

Marshallmarshallese answered 24/9, 2013 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.