Log axis with percentage tick labels
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi, just starting to use matlab here, running a few experimental calculations and pretty excited so far.
I'm currently struggling with displaying a graph of cumulative relative returns where changing value axis scale to log seems to defeat percentage formatting and override it with a default format, making presentation hard to grasp.
figure;
ax = axes;
plot(sourceData.Date, sourceData.ResultCompound);
ytickformat(ax, 'percentage'); % also tried ytickformat(ax, '%0.2f%%')
ax.YScale = 'log'; % no problem with default/'linear'
So my question is, is there a way to make log-scaled graphs with percentage tick labels?
댓글 수: 0
채택된 답변
Star Strider
2020년 9월 24일
I am not certain what you want to do.
Try this:
x = linspace(-2, 2, 50); % Create Data
y = exp(-(x).^2/2); % Create Data
figure
semilogy(x, y)
grid
yt = get(gca, 'YTick');
ytl = compose('%.0f%%', yt*100)
set(gca, 'YTick',yt, 'YTickLabel',ytl)
.
댓글 수: 2
Star Strider
2020년 9월 24일
My pleasure!
I am not certain what you want. It is straightforward to define new ticks and tick labels.
This one change to my original code does that:
x = linspace(-2, 2, 50); % Create Data
y = exp(-(x).^2/2); % Create Data
figure
semilogy(x, y)
grid
yt = get(gca, 'YTick');
ytn = linspace(min(yt), max(yt), 4); % Define Nes ‘ytick’ Values
ytl = compose('%.1f%%', ytn*100)
set(gca, 'YTick',ytn, 'YTickLabel',ytl)
The new tick values always need to be within the range of the current tick values, however within that range they can be anything.
추가 답변 (1개)
Steve Eddins
2020년 9월 24일
From what I can tell, the ruler object ignores the TickLabelFormat property (which is set by ytickformat) when the Scale is 'log'. I will record an enhancement/documentation request about this.
As a workaround, you can set the tick labels directly to whatever strings you want by using yticklabels. Try something like this:
yticklabels(string(yticks) + "%")
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!