Remove the bottom x-axis line of a plot

380 visualizzazioni (ultimi 30 giorni)
TTA
TTA il 26 Mag 2022
Modificato: Les Beckham il 4 Ott 2024
Hi,
Please how can I remove the bottom line of X-axis of a plot and leave the top x-axis line
Thanks

Risposta accettata

TTA
TTA il 26 Mag 2022
Please I want to do something like this that will remove only the bottom x-axis
  4 Commenti
DLR
DLR il 4 Ott 2024
Removing the box also seems like it removes the right y-axis. Is there any way to avoid this?
Les Beckham
Les Beckham il 4 Ott 2024
Modificato: Les Beckham il 4 Ott 2024
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"

Accedi per commentare.

Più risposte (1)

Veronica Taurino
Veronica Taurino il 26 Mag 2022
Modificato: Veronica Taurino il 26 Mag 2022
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 Commenti
TTA
TTA il 26 Mag 2022
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
Veronica Taurino
Veronica Taurino il 26 Mag 2022
Modificato: Veronica Taurino il 26 Mag 2022
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')

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by