Change the format of x axis in a Kernel density plot.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
alberto caracciolo
am 16 Jul. 2019
Beantwortet: Steven Lord
am 17 Jul. 2019
Hi all,
I made this plot using a Kernel density function
x = [B];
[f,xi] = ksdensity(x,'bandwidth', bw);
plot(xi,f, 'g');
What i would like to do is to change the x-axis labels into 10 base power. For example, instead of having 0 i would like to have 10^2 and so on. The final result shold be something similar to this figure:
Thank you
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 17 Jul. 2019
I suspect when you called semilogx as you said in your answer that probably should have been a comment you plotted on a linear axes first (with plot), turned hold on, then tried plotting a second time with semilogx. If you do that, hold will prevent semilogx from making the axes have a log scaled X axis.
To avoid this, either don't try to plot two graphs on the same axes with hold on but instead plot just the log scale data or change the X axes scale to 'log' directly, without calling semilogx. The hold function will prevent MATLAB from automatically switching the scale, but it won't prevent MATLAB from switching the scale if you explicitly order it to do so.
This example will not switch the X axes scale.
figure
plot(1:10, 1:10)
hold on
semilogx(1:10, 10:-1:1)
This will.
figure
h = plot(1:10, 1:10);
hold on
semilogx(1:10, 10:-1:1);
% Get the axes containing the line
ax = ancestor(h, 'axes');
% Explicitly order MATLAB to change the scale
ax.XScale = 'log';
This will too.
figure
semilogx(1:10, 10:-1:1);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!