How to avoid marker clipping while saving two axis figure to pdf?
20 views (last 30 days)
Show older comments
Hi everyone,
I have some trouble while exporting a two axis figure to pdf. The following example code works great while creating the figure in Matlab. But in the generated pdf-file all my red markers on the x-axis get cut off (see screenshot). Curiously this problem only occures, when I use a two axis plot

fig = figure;
x = linspace(0,25);
y = sin(x/2);
marker = linspace(0,25,5);
yyaxis left
plot(x,y,'g');
hold on;
r = x.^2/2;
yyaxis right
plot(x,r,'b');
hold on;
plot(marker,0,'rx','Markersize', 8);
saveas(gcf,'myfigure.pdf');
Can anyone please help me out here?
0 Comments
Accepted Answer
jonas
on 13 Sep 2018
Edited: jonas
on 13 Sep 2018
Not the first time I see clipping issues with plotyy. Simple solution, avoid using plotyy
% Create two axes
ax(1)=axes('color','none');hold on
ax(2)=axes('yaxislocation','right','xcolor','none','color','none');hold on
x = linspace(0,25);
y = sin(x/2);
marker = linspace(0,25,5);
% Toggle left
axes(ax(1))
plot(x,y,'g');
hold on;
r = x.^2/2;
% Toggle right
axes(ax(2))
plot(x,r,'b');
hold on;
plot(marker,0,'rx','Markersize', 8);
% Link axes, IMPORTANT!
linkaxes(ax,'x')
% Save
saveas(gcf,'myfigure.pdf');
Possibly, the reason for the yyaxis annoying clipping is that the default clippingstyle is set to 'rectangle' instead of the normal '3dbox'. Changing the clippingstyle is however difficult, as it keeps reverting back to 'rectangle' when toggling yyaxis.
0 Comments
More Answers (2)
See Also
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
