Equally spaced markers in a loglog plot
조회 수: 15 (최근 30일)
이전 댓글 표시
Hello,
I have the following problem: I am plotting a line in a loglog plot. However since the figure will be printed in black&white I want additional markers to be on the line. Is there a simple way to have the makers equally spaced in the loglog scale. The way I am doing it right now is:
x=linspace(1000,10000,1000);
data=x.^-0.5;
loglog(x,data)
hold on
scatter(x(1:100:end),data(1:100:end));
But obviously this makes the marker not equally spaced. I could make a function for 'data' and than feed it with the right values,like this:
xx=(10*ones(1,11)).^(3:0.1:4);
data_fun=@(a) a.^-0.5;
figure()
loglog(x,data)
hold on
scatter(xx,data_fun(xx));
but I was wondering if there is a simpler way, since that would mean creating a lot of functions (in my case). Thx Vali
댓글 수: 0
채택된 답변
Chad Greene
2014년 10월 13일
편집: Chad Greene
2014년 10월 13일
x=linspace(1000,10000,1000);
data=x.^-0.5;
loglog(x,data)
hold on
evenMarkers(x,data,11);
where evenMarkers is this function:
function [xmarkers,ymarkers,h] = evenMarkers(x,y,NumMarkers)
xmarkers = logspace(log10(x(1)),log10(x(end)),NumMarkers);
ymarkers = interp1(x,y,xmarkers);
h = plot(xmarkers,ymarkers,'ko');
end
댓글 수: 2
Matthew
2019년 5월 8일
Excellent solution Chad, but I am going to suggest a small improvement. If plotting linearly spaced data on a loglog plot, say the results from a fft of a time signal, the distance between points at low frequencies can be quite large. Doing the fit in linear space causes an issue here because a line in linear space is not a line in log space. So I recommend the following adjustment:
function [xmarkers,ymarkers] = evenMarkers(x,y,NumMarkers)
xmarkers = logspace(log10(x(1)),log10(x(end)),NumMarkers);
ymarkers = interp1(log10(x),log10(y),log10(xmarkers));
ymarkers = 10.^(ymarkers);
end
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Log Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!