How to set minor ticks for any particular position?

108 visualizzazioni (ultimi 30 giorni)
I need to set xticks from -4000 to 4000. I use the following command to set ticks at every 500.
xticks(-4000:500:4000)
But I need xticks at 100, 250, 750. How can set the ticks at those certain points?

Risposta accettata

Voss
Voss il 16 Mag 2022
To set minor ticks at 100, 250, 750 (as the title of the question implies):
figure();
xticks(-4000:500:4000);
set(gca(),'XMinorTick','on')
set(get(gca(),'XAxis'),'MinorTickValues',[100 250 750])
xlim([-1500 1500]) % to see the effect
Or, to set xticks at 100, 250, 750 and -4000:500:4000 (as the question itself asks):
figure();
xticks(sort([-4000:500:4000 100 250 750]))
xlim([-1500 1500]) % to see the effect
  2 Commenti
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA il 17 Mag 2022
Modificato: ANANTA BIJOY BHADRA il 17 Mag 2022
I can place them but they overlaps each other. Can I change the size of the of the values 100 250 750 so they does not overlap? I used the 2nd way.
Voss
Voss il 17 Mag 2022
You can try this:
xticks(sort([-4000:500:4000 100 250 750]))
xlim([-4000 4000]) % to see the effect
xtl = xticklabels();
idx = ismember(xtl,{'100' '250' '750'});
xtl(idx) = strcat('\fontsize{6}',xtl(idx));
xticklabels(xtl)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by