Remove the bottom x-axis line of a plot

Hi,
Please how can I remove the bottom line of X-axis of a plot and leave the top x-axis line
Thanks

 Accepted Answer

TTA
TTA on 26 May 2022
Please I want to do something like this that will remove only the bottom x-axis

4 Comments

Use this to remove even the x-tick label as in the above picture:
plot(1:10) % your plot here
set(gca,'XAxisLocation','top', 'box','off', 'XTick', [])
If you need labels:
set(gca,'XAxisLocation','top', 'box','off')
Look here and here
Thank you very much.
It works
Removing the box also seems like it removes the right y-axis. Is there any way to avoid this?
If you just want to restore the right side of the box (without ticks or tick labels on the right side), you could do this:
plot(1:10)
set(gca,'XAxisLocation','top', 'box','off')
xline(max(xlim)) % <<< this draws the right side of the "box"

Sign in to comment.

More Answers (1)

In general, to move your x-asix on top:
set(gca,'XAxisLocation','top')
To hide the axis:
set(gca,'xtick',[])
or
h = gca;
h.XAxis.Visible = 'off';

2 Comments

Thanks Vero,
In this case will I be able to turn off only the bottom x-axis off and leave the top x-axis?
Thanks
I gave you more options because your need is not clear to me. You should try one of the above. I think the first one could be fine:
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
set(gca,'XAxisLocation','top')

Sign in to comment.

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Tags

Asked:

TTA
on 26 May 2022

Edited:

on 4 Oct 2024

Community Treasure Hunt

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

Start Hunting!