Customise axis ticks and ticks labels with exponential notation

 Réponse acceptée

dpb
dpb le 13 Août 2022
Modifié(e) : dpb le 13 Août 2022
See <Include Superscript and Subscript in Axis Labels> example at <xlabel>
Moral: Read doc including looking at examples...

3 commentaires

thanks @dpb! I found a solution for my case:
xticks([10^0 10^(0.5) 10^1 10^(1.5) 10^2 10^(2.5)])
xticklabels({'10^0','10^{0.5}','10^1','10^{1.5}','10^2','10^{2.5}'})
yticks([10^(2.9),10^(3),10^(3.1),10^(3.2)])
yticklabels({'10^{2.9}','10^{3}','10^{3.1}','10^{3.2}'})
set(gca, 'XScale', 'log','YScale', 'log')
You can make things a little less specific and typing of duplicated stuff using MATLAB array syntax --
p=[0:0.5:2.5]; % the desired powers
xtk=10.^p; % evaluate for ticks, limits
xlim([xtk(1) xtk(end)]) % set limits to match
xticks(xtk) % and the desired tick locations
xticklabels(compose('10^{%g}',p)) % and put on the annotation
This lets you set any arbitrary set of exponents in the p array; the rest then follows automagically...
I like the "automagically" term ;-)
...thanks a lot @dpb, I will use your piece of code, better than what I wrote :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Question posée :

Sim
le 13 Août 2022

Commenté :

Sim
le 16 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by