4

只是想知道是否有人对我遇到的问题有任何想法。

我有大量数据需要显示在一个图表上。两条粗体和实线的理论线显示在顶部,然后绘制出收敛到这些线的 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));

但这显然会导致李子表现得神经质。每个十年都有我想要的点数,但由于它是一个线性分布,这些点往往在对数尺度上十年的高端聚集。

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

4

2 回答 2

3

我认为最简单的方法是使用LOGSPACE函数为您的数据生成一组索引。例如,要创建一组 100 个点的对数间隔,从 1 到 N(数据中的点数),您可以尝试以下操作:

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

像这样创建对数间隔的索引将导致从向量末尾相对于起点选择更少的值,从而更严格地修剪向量末尾的值并改善对数图的外观。因此,它对按升序排序的向量最为有效。

于 2010-04-21T05:11:49.437 回答
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),'.')
于 2010-04-21T02:24:52.603 回答