Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User-defined scaling in gnuplot for y axis (equivalent to set logscale y)

Tags:

gnuplot

I have defined a function f() that I would like to use for scaling, in a similar way to logscale (but f() is not a logarithmic function). Is there a way to just do it automatically, like set fscale y?

Otherwise I tried to plot the scaled function:

plot 'data' using 1:(f($2))

but then the scale on the y axis is obviously wrong. Can I use my function to rescale the y axis somehow?

I would like to avoid having to set all the ticks and their labels manually (because I will use this script for a lot of different plots).

like image 216
Grzenio Avatar asked Mar 08 '12 12:03

Grzenio


Video Answer


1 Answers

If your data does not vary much, you could insert the tics semi-automatically by prepending the plot command by set ytics ({"<label>"} <pos> {<level>} {,{"<label>"}...)

Just use appropriate number of points so that the plot will be clear.

Example:

$ cat ex.data 
0 0
1 3
2 2.2
5 5
7 1.2
9 4
12 9
15 5

so our y-data ranges from 0 to 9.

 $ gnuplot

         G N U P L O T
         Version 4.4 patchlevel 3
         last modified March 2011
         System: Linux 3.2.0-24-generic

         Copyright (C) 1986-1993, 1998, 2004, 2007-2010
         Thomas Williams, Colin Kelley and many others

         gnuplot home:     http://www.gnuplot.info
         faq, bugs, etc:   type "help seeking-assistance"
         immediate help:   type "help"
         plot window:      hit 'h'

 Terminal type set to 'wxt'
 gnuplot> f(x) = x**2
 gnuplot> set yrange [0:f(10)]
 gnuplot> set ytics ("0" f(0), "5" f(5), "7.5" f(7.5), "10" f(10))
 gnuplot> plot "ex.data" u 1:(f($2)) w l

The result:

example plot

like image 190
Jari Laamanen Avatar answered Nov 13 '22 04:11

Jari Laamanen