jpc
jpc

Reputation: 139

Gnuplot: Linear scaling data from a column to a specific range

I am making a circle chart using gnuplot. The first two columns plot a point on the XY plane, and I want the third to dictate the size of the circle. The third column has data between 1000-5000, so I have been using:

plot 'foo.csv' u 1:2:($3/100) w circles

which works ok, but I am wondering if there is a better way.

I made the same chart using d3.js, where I used the scaleLinear() function to map the data from column three (the domain, 0-max value) to the range (1-10). Is there anything similar in gnuplot, where I can map my data to a specific range like this?

Upvotes: 1

Views: 298

Answers (1)

Ethan
Ethan

Reputation: 15143

The "stats" command can the information required for scaling. If you want to scale input range [0:max] to effective [0:10] this would do the trick:

stats 'foo.csv' using 3 nooutput
plot 'foo.csv' using 1:2:($3 * 10./STATS_max) w circles

If the linear range does not necessarily start at zero then it may be worth defining a scaling function first.

stats 'foo.csv' using 3 nooutput
scale(y) = 10. * (y - STATS_min) / (STATS_max - STATS_min)
plot 'foo.csv' using 1:2:(scale($3)) with circles

Upvotes: 1

Related Questions