Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set x-axis 'visible' to 'off'

2,473 views
Skip to first unread message

Markus Due Jakobsen

unread,
Oct 23, 2008, 6:21:01 AM10/23/08
to
Hi

Is it possible to remove the x-axis from a 2d plot?
I know how to remove the x-axis ticks:..
set(gca, 'XTickLabelMode', 'Manual')
set(gca, 'XTick', [])
..but not the x-axis line.
Is there someway to set 'visibility' of the x-axis (line) to 'off'?

Thanks
Markus

Message has been deleted

Pete

unread,
Dec 9, 2011, 7:23:08 AM12/9/11
to
I just found myself needing to do this. In case it is of use to anybody, I neded up doing the following (Mac OS, Matlab R2010a):


1. First I tried:
set(gca,'xcolor',[1 1 1]);

This is great, except it caused the xlabel to also be changed to white when I resized or save the figure

2. Next I tried
set(gca,'xcolor',[1 1 1]);
set(get(gca,'xlabel'),'Color',[0 0 0]); % preserve colour on xlabel
set(figHandle,'ResizeFcn',@(src,event)set(get(gca,'xlabel'),'Color',[0 0 0])); % prevent reset on resize

This sorted out the resize problem, but still when I saved to .eps (using -despc2) the xlabel colour would be reset to the axis colour

3. Finally then, I ended up just drawing a white line over the x-axis, thus:
P = get(gca,'Position');
hLine = annotation('line',[P(1) P(1)+P(3)],[P(4) P(4)],'Color',[1 1 1],'LineWidth',3); % draw a white line over the x axis
% nudge the line so that it covers the axis
set(hLine,'Units','Pixels')
set(hLine,'Position',get(hLine,'Position')+[1 1.5 0 0]) % nudge values might need to be tweaked
set(hLine,'Units',get(gca,'Units'))

This is an ungainly hack, but did the job for me.
0 new messages