Remove only axes without affecting ticks and cue marks.

Is there a way to remove only axes in a Matlab shape without affecting ticks and label marks.

I know that box toggles the lines and ticks of the top and right axes, and this works fine for me.
But my problem is that I want to delete the bottom and left lines (only lines!), But keeping ticks and labels.

Any tricks?

+7
matlab plot line axis matlab-figure
source share
4 answers

There is another undocumented way (for MATLAB R2014b and later) of deleting lines by changing the 'LineStyle' ruler to 'none' .

Example:

 figure; plot(1:4,'o-'); %Plotting some data pause(0.1); %Just to make sure that the plot is made before the next step hAxes = gca; %Axis handle %Changing 'LineStyle' to 'none' hAxes.XRuler.Axle.LineStyle = 'none'; hAxes.YRuler.Axle.LineStyle = 'none'; %Default 'LineStyle': 'solid', Other possibilities: 'dashed', 'dotted', 'dashdot' 

output


This is different from Dan's answer , which uses the โ€œvisibleโ€ rulers property.

+3
source share

Solution for Matlab versions prior to R2014b

You can enter a new white bounding box and place it on top.

 // example data x = linspace(-4,4,100); y = 16 - x.^2; plot(x,y); hold on ax1 = gca; set(ax1,'box','off') %// here you can basically decide whether you like ticks on %// top and on the right side or not %// new white bounding box on top ax2 = axes('Position', get(ax1, 'Position'),'Color','none'); set(ax2,'XTick',[],'YTick',[],'XColor','w','YColor','w','box','on','layer','top') %// you can plot more afterwards and it doesn't effect the white box. plot(ax1,x,-y); hold on ylim(ax1,[-30,30]) 

It is important to deactivate the ticks of the second axes in order to keep the firest ticks.

enter image description here

In Luis Mendoโ€™s solution, the drawn lines are fixed and remain in their original position if you subsequently change the properties of the axes. This will not happen here; they are adapting to new limits. Use the correct pen for each team and there will be no problems.

Dan's solution is simpler, but not applicable for Matlab versions prior to R2014b .

+8
source share

Yair Altman Undocumented Matlab demonstrates a cleaner way to do this using undocumented axes:

 plot(x,y); ax1 = gca; yruler = ax1.YRuler; yruler.Axle.Visible = 'off'; xruler = ax1.XRuler; xruler.Axle.Visible = 'off'; %// note you can do different formatting too such as xruler.Axle.LineWidth = 1.5; 

A good feature of this approach is that you can separately format the x and y axis axes.

+8
source share

You can erase the axes by plotting a white line on them:

 plot(1:4,1:4) %// example plot box off %// remove outer border hold on a = axis; %// get axis size plot([a(1) a(2)],[a(3) a(3)],'w'); %// plot white line over x axis plot([a(1) a(1)],[a(3) a(4)],'w'); %// plot white line over y axis 

Result:

enter image description here


As @SardarUsama noted, in recent versions of Matlab, you may need to adjust the line width to cover the axes:

 plot(1:4,1:4) %// example plot box off %// remove outer border hold on a = axis; %// get axis size plot([a(1) a(2)],[a(3) a(3)],'w', 'linewidth', 1.5); %// plot white line over x axis. %// Set width manually plot([a(1) a(1)],[a(3) a(4)],'w', 'linewidth', 1.5); 
+2
source share

All Articles