Fill command for logarithmic plots axes labels

1 Ansicht (letzte 30 Tage)
Kristy Hansen
Kristy Hansen am 2 Okt. 2014
Kommentiert: Kristy Hansen am 3 Okt. 2014
Hello,
I would like to label my axes in the identical way to which is done using the semilogx command. This involves 10 with a superscript of the appropriate power. I do not want to label using scientific notation or 10^x (I don't want the "^" symbol and I want the "x" to be raised to a superscript).
I am using the fill command as follows:
hf1 = fill(log10([f_n(2:end); flipud(f_n(2:end))]),log10([max_ind_1(2:end)'; flipud(min_ind_1(2:end)')]),[0.7 0.7 0.7]);
Thank you in advance if you can help!
  1 Kommentar
Star Strider
Star Strider am 2 Okt. 2014
Please post some or all of your data used in your code. It’s difficult to understand what your code is doing without it.
You will need to use the text function, but I can’t be more specific without understanding in greater detail what you want to do and how it relates to your plot.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 2 Okt. 2014
To automate dpb's suggestion, you can use my tick2text function:
plot(1:10, rand(10,1));
tick2text(gca, 'axis', 'x', 'xformat', @(x) sprintf('10^{%.0f}',x), 'convert', true);
  1 Kommentar
Kristy Hansen
Kristy Hansen am 3 Okt. 2014
Thank you! Your function is very nice and gave me exactly what I wanted :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 2 Okt. 2014
Bearbeitet: dpb am 2 Okt. 2014
The basic deal is for some unbeknownst and unfathomable reason, TMW hasn't implemented the Tex/LaTex interpreter in the ticklabel property renderer. That being so, you must write them yourself with text
As an example of the idea, try the following--the same thing works for whatever plot functional form is used...
axes % make an axes object
xlim([0 10]) % convenient limits
xt=get(gca,'xtick'); % get the values from the ticks
set(gca,'xticklabel','') % clear existing tick labels
xlab=num2str(xt.','{10}^{%d}'); % TeX label string array of exponential form
text(xt,-0.05*ones(size(xt)),xlab,'horizontalalign','center') % and write
  1 Kommentar
Kristy Hansen
Kristy Hansen am 3 Okt. 2014
Thank you for your answer and for enlightening me on why things weren't working!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by