Change the format of x axis in a Kernel density plot.
조회 수: 13 (최근 30일)
이전 댓글 표시
![untitled.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230033/untitled.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230034/Untitled.png)
Thank you
댓글 수: 0
채택된 답변
추가 답변 (1개)
Steven Lord
2019년 7월 17일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!