Trimming data for better viewing on log charts - Matlab

just wondering if anyone has any ideas about the problem I have.

I have enough data that should be displayed on one chart. Upstairs, two theoretical lines are displayed, which are shown in bold and solid, then 10 graphic data sets that converge to these lines using a different identifier (for example, + or o or a square, etc.). These graphs are on a scale that increases to 1e6. The first few decades of the graph (<1e3) look great, but as all data collections converge (> 1e3), it's really hard to figure out what data is.

There are over 1000 data point points per decade that I can crop linearly to some extent, but if I do this too much, the lower end of the graph will suffer in resolution.

What I would like to do is break the trap that is the strongest at the top end, working to 0. My question is: how can I get a logarithmically scaled index vector, not a linear one?

My initial assumption was that since my data is lenear, I could just use a linear index to shorten, which would lead to something similar (but for all decades):

//%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)); 

But this leads to the fact that prunes are furious. Each decade has a number of points that I would like, but since this is a linear distribution, these points tend to shrink at the top of the decade on a magazine-wide basis.

Any ideas on how I can do this?

+4
source share
2 answers

I think the easiest way to do this is to use the LOGSPACE function to generate a set of indexes into your data. For example, to create a set of 100 points, logarithmically spaced from 1 to N (the number of points in your data), you can try the following:

 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 

Creating a logarithmically spaced index like this will cause fewer values โ€‹โ€‹to be selected from the end of the vector relative to the beginning, thereby decreasing the values โ€‹โ€‹more strictly towards the end of the vector and improving the appearance of the log graph. Therefore, it will be most effective with vectors sorted in ascending order.

+3
source

As I understand it, the problem is that your x values โ€‹โ€‹are linearly distributed, so if you plot them logarithmically, there are even more data points in the โ€œhigherโ€ decades, so the markers are very close to each other. For example, if x goes from 1 to 1000, in the first decade 10 points, in the second - 90, and in the third - 900. You want to have, say, 3 points per decade.

I see two ways to solve the problem. The easier it is to use different colored lines instead of different markers. This way you are not sacrificing any data points, and you can still distinguish everything.

The second solution is to create an unevenly spaced index. Here is how you can do it.

 %# 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),'.') 
+1
source

Source: https://habr.com/ru/post/1307506/


All Articles