Equally spaced markers in a loglog plot

17 ビュー (過去 30 日間)
Vali
Vali 2014 年 10 月 13 日
コメント済み: Matthew 2019 年 5 月 8 日
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

採用された回答

Chad Greene
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 件のコメント
Vali
Vali 2014 年 10 月 13 日
seems like a very elegant solution. I will use that.
Thank you Chad!
Matthew
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 件)

Chad Greene
Chad Greene 2014 年 10 月 13 日
You can use logspace. :)
  1 件のコメント
Vali
Vali 2014 年 10 月 13 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLog Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by