Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Gnuplot's (auto)range values and modify them to add some margin?

Tags:

Using the standard plot command, I get, what I want except that the yrange is set automatically from (eg) 275 to 300.

Unfortunately, I have several data points with y-coordinate 300, such that they are not visible (due to border lines, etc.).

So, is there any way to set the maximum yrange such that it is always the maximum data plus e.g. 5 units?

Using autoscale, the yrange is set to 275:300. Setting explicitly the range to 275:305 would work for one data file but not for others. So I need some generic method to determine the max-data point and set the yrange larger.

like image 240
Matthias Avatar asked Sep 07 '11 07:09

Matthias


People also ask

What is key in gnuplot?

The set key enables a key (or legend) describing plots on a plot. The contents of the key, i.e., the names given to each plotted data set and function and samples of the lines and/or symbols used to represent them, are determined by the title and with options of the {s}plot command.

Does gnuplot support multiple y axes on a single plot?

5.9 Does gnuplot support multiple y-axes on a single plot? Yes. 2D plots can have separate x axes at the bottom (x1) and top (x2), and separate y axes at the left (y1) and right (y2).

Why gnuplot?

gnuplot can read data in multiple formats, including ability to read data on the fly generated by other programs (piping), create multiple plots on one image, do 2D, 3D, contour plots, parametric equations, supports various linear and non-linear coordinate systems, projections, geographic and time data reading and ...

What files can gnuplot open?

Gnuplot can read binary data files. However, adequate information about details of the file format must be given on the command line or extracted from the file itself for a supported binary filetype. In particular, there are two structures for binary files, a matrix binary format and a general binary format.


2 Answers

set offsets <left>, <right>, <top>, <bottom> 

will do. Note the scale follows the data scale, so it will eventually depend on the data you want to plot. Alternatively, you can use set offsets graph ... to use fraction of the plot size instead.

like image 150
Sunhwan Jo Avatar answered Sep 29 '22 07:09

Sunhwan Jo


There are Gnuplot defined values GPVAL_Y_MAX and GPVAL_DATA_Y_MAX (also GPVAL_Y_MIN, GPVAL_DATA_Y_MIN ...). After your plot, the maximum value will be stored in these values. So you can plot your data then set yrange GPVAL_Y_MAX+(GPVAL_Y_MAX-GPVAL_Y_MIN)*0.05. At this time you plot you data for the second time. This time you just get what you want. The following is my code.

     reset     plot "data.dat" u 1:2 #To get the max and min value     MAX=GPVAL_Y_MAX     MIN=GPVAL_Y_MIN     set yrange [MIN-(MAX-MIN)*0.05:MAX+(MAX-MIN)*0.05]     #Add a fixed value is not a good idea, so I use a relative one     set term png     set output "out.png"     plot "data.dat" u 1:2 w p notitle #This plot will create a file     #named out.png which is waht you want. 

I learned the method from this article--http://gnuplot-surprising.blogspot.com/2011/09/advanced-background-color-1.html

like image 34
hsxz Avatar answered Sep 29 '22 07:09

hsxz