3
votes

I have a large set of data points from x = 1 to x = 10e13 (step size is fixed to about 3e8). When I try to plot them using a logscale I certainly get an incredible huge point-density towards the end. Of course this affects my output plots since postscript and svg files (holding each and every data point) are getting really big.

Is there a way to tell gnuplot to decrease the data density dynamically?

Sample data here. Shows a straight line using logarithmic x-axis.

2
I think I might have an idea. Could you provide some sample data?Tom Fenech
added a link in the questionMrD

2 Answers

2
votes

Usually, for this kind of plots, one can use a filter function which selects the desired points and discards all others (sets their value to 1/0:

Something like:

plot 'sample.dat' using (filter($1) ? $1 : 1/0):2

Now you must define an appropriate filter function to change the data density. Here is a proposal, with pseudo-data, although you might for sure find a better one, which doesn't show this typical logarithmic pattern:

set logscale x
reduce(x) = x/(10**(floor(log10(x))))
filterfunc(x) = abs(log10(sc)+(log10(x) - floor(log10(x))) - log10(floor(sc*reduce(x))))
filter(x) = filterfunc(x) < 1e-5 ? x : 1/0

set multiplot layout 1,2
sc = 1
plot 'sample.data' using (filter($1)):2 notitle
sc = 10
replot

The variable sc allows to change the density. The result is (with 4.6.5) is:

enter image description here

1
votes

I did some work inspired by Christoph's answer and able to get equal spacing in log scale. I made a filtering, if you have numbers in the sequence you can simply use Greatest integer function and then find the nearest to it in log scale by comparing the fraction part. Precision is tuned by precision_parameter here.

precision_parameter=100
function(x)=(-floor(precision_parameter*log10(x))+(precision_parameter*log10(x)))

Now filter by using the filter function defined below

density_parameter = 3.5
filter(x)=(function(x) < 1/(log10(x))**density_parameter &  function(x-1) > 1/(log10(x))**density_parameter ) ? x : 1/0
set datafile missing "NaN"

Last line helps in plotting with line point. I used x and x-1 assuming the xdata is in arithmetic progression with 1 as common difference, change it accordingly with your data. Just replace x by filter(x) in the plot command.

plot 'sample_data.dat' u (filter($1)):2 w lp