2010-04-21 45 views
4

只是想知道如果任何人有任何关于我有问题的想法。修剪数据更好地查看loglog图 - Matlab

我有相当数量的数据需要显示在一张图上。在顶部显示两条粗体和实心的理论线,然后聚合到这些线的10个实验数据集被绘制成图,每个使用不同的标识符(例如+或o或方形等)。这些图表的对数尺度最高可达1e6。该图的前几十年(< 1e3)看起来很好,但是由于所有数据集都收敛(> 1e3),所以很难看到数据是什么。

每十年有超过1000个数据点,我可以在一定程度上进行线性修剪,但如果我这样做太多,图表的下端将会出现分辨率问题。

我想要做的是对数修剪,在最高端最强,回到0.我的问题是:如何获得对数缩放索引向量而不是线性索引向量?

我最初的设想是,我的数据是实现线性我可以只使用一个线性指数修剪,从而导致这样的事情(而且对所有几十年):

//%grab indicies per decade 
ind12 = find(y >= 1e1 & y <= 1e2); 
indlow = find(y < 1e2); 
indhigh = find(y > 1e4); 
ind23 = find(y >+ 1e2 & y <= 1e3); 
ind34 = find(y >+ 1e3 & y <= 1e4); 

//%We want ind12 indexes in this decade, find spacing 
tot23 = round(length(ind23)/length(ind12)); 
tot34 = round(length(ind34)/length(ind12)); 

//%grab ones to keep 
ind23keep = ind23(1):tot23:ind23(end); 
ind34keep = ind34(1):tot34:ind34(end); 

indnew = [indlow' ind23keep ind34keep indhigh']; 

loglog(x(indnew), y(indnew)); 

但这会导致剪枝明显表现出跳跃式的表现。每个十年都有我想要的点数,但由于它是一个线性分布,所以这些点在对数尺度上趋于在十年的高端结块。

关于如何做到这一点的任何想法?

+1

我不明白你的问题 - 你可以发布一个示例图吗? – mtrw 2010-04-21 02:04:31

回答

3

我认为这样做最简单的方法是使用LOGSPACE函数生成一组索引到你的数据。例如,要创建一组从1数间隔至N(点的数据的数量)100分,你可以尝试以下方法:

indnew = round(logspace(0,log10(N),100)); %# Create the log-spaced index 
indnew = unique(indnew);     %# Remove duplicate indices 
loglog(x(indnew),y(indnew));    %# Plot the indexed data 

创建这样一个对数间隔的指数将导致从矢量的末端相对于起点选择更少的值,从而在矢量的末端更严重地修剪值并改善对数图的外观。因此,对于按升序排序的向量来说,它将是最有效的。

+0

非常好!我每天都会学到新的东西。 – Jonas 2010-04-21 05:13:27

+0

是的!我最初尝试使用logspace,但不知道如何正确地执行此任务。谢谢,虽然乔纳斯的解决方案有效;这可能更具说服力。 – Geodesic 2010-04-21 05:31:56

1

我对这个问题的理解方式是,你的x值是线性间隔的,所以如果你以对数形式绘制它们,“更高”的几十年里就有更多的数据点,这样标记就彼此非常接近。例如,如果x从1到1000,第一个十年中有10个点,第二个90个,第三个900个。你希望每十年有3分,而不是。

我看到两种方法来解决这个问题。更容易的是使用不同颜色的线条而不是不同的标记。因此,你不会牺牲任何数据点,并且你仍然可以区分一切。

第二种解决方案是创建不均匀间隔的索引。这是你如何做到的。

%# create some data 
x = 1:1000; 
y = 2.^x; 

%# plot the graph and see the dots 'coalesce' very quickly 
figure,loglog(x,y,'.') 

%# for the example, I use a step size of 0.7, which is `log(1)` 
xx = 0.7:0.7:log(x(end)); %# this is where I want the data to be plotted 

%# find the indices where we want to plot by finding the closest `log(x)'-values 
%# run unique to avoid multiples of the same index 
indnew = unique(interp1(log(x),1:length(x),xx,'nearest')); 

%# plot with fewer points 
figure,loglog(x(indnew),y(indnew),'.') 
+0

我正在提交的日志不允许颜色,因此标记 - 但您的解决方案完美工作;谢谢! – Geodesic 2010-04-21 03:19:24

+0

祝您好运! – Jonas 2010-04-21 03:51:36