Equally spaced markers in a loglog plot

17 Ansichten (letzte 30 Tage)
Vali
Vali am 13 Okt. 2014
Kommentiert: Matthew am 8 Mai 2019
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

Akzeptierte Antwort

Chad Greene
Chad Greene am 13 Okt. 2014
Bearbeitet: Chad Greene am 13 Okt. 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 Kommentare
Vali
Vali am 13 Okt. 2014
seems like a very elegant solution. I will use that.
Thank you Chad!
Matthew
Matthew am 8 Mai 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Chad Greene
Chad Greene am 13 Okt. 2014
You can use logspace. :)
  1 Kommentar
Vali
Vali am 13 Okt. 2014
logspace is a nice function to help creating the variable xx so instead of
xx=(10*ones(1,11)).^(3:0.1:4);
I can do
xx=logspace(3,4,10)
but that still does not solve the problem of plotting the markers, at least I don't understand how.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Log Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by