Equally spaced markers in a loglog plot
16 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Chad Greene
on 13 Oct 2014
Edited: Chad Greene
on 13 Oct 2014
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 Comments
Matthew
on 8 May 2019
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
More Answers (1)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!