Change the format of x axis in a Kernel density plot.

8 visualizaciones (últimos 30 días)
alberto caracciolo
alberto caracciolo el 16 de Jul. de 2019
Respondida: Steven Lord el 17 de Jul. de 2019
untitled.jpg
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:
Untitled.png
Thank you

Respuesta aceptada

the cyclist
the cyclist el 16 de Jul. de 2019
Instead of the plot command, use semilogx.

Más respuestas (1)

Steven Lord
Steven Lord el 17 de Jul. de 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);

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by