Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

automatically scaling Gnuplot graphs to leave a percentage of free space to axis

4,454 views
Skip to first unread message

bbcda

unread,
Mar 15, 2010, 7:07:20 PM3/15/10
to
Dear all!

I am currently developing a relatively complex Gnuplot script to
automatically plot a bunch of files (I will have to use the template by
hand and rerun it - but I would like it to be as easy as possible...).
My problem is: I am using data from a file, subtract two columns in the
file from each other (and I have to multiply them with a factor), and
then plot them with labelled peaks... In other words: relatively
complex data, and I will label the peak.
What I need now is a convenient way to leave some room between my data
points and the plot axis; unfortunately, Gnuplot would automatically
scale the yrange, so that the maximum value lies on the top x-axis... I
know that I could set a padding for this using "set offsets", but the
problem is that this command only allows to give ABSOLUTE values (in
terms of the axis values) for the room Gnuplot has to leave, and my
data values vary very much between all the files I'd like to plot, and
thus this would be another parameter I'd need to take care of during
plotting and replotting (which I'd like to prevent).

Instead, I'd like Gnuplot to automatically read the maximum und minimum
value of the plot range (Gnuplot must have that value internally to
autoscale the yaxis anyways, I believe...), and then tell him to leave
e.g. 10 % of room to both sides (top and bottom). In meta code, what
I'd need is sth. like this:

plot [:][YMIN+(YMAX-YMIN)*0.1:YMAX+(YMAX-YMIN)*0.1] "data.txt" using
1:(SOME FUNCTION OF $2 AND $3)

where "SOME FUNCTION OF $2 AND $3" is the function that calculates the
plotted values from the entries in column 2 and 3 of the input file,
and YMIN and YMAX are the maximum values in those data that are to be
plotted.

Now - I didn't find anything about this - and really I only start to
understand how much I do not yet know about Gnuplot... It would be
really great if somebody could give a hint on how to solve this last of
my issues... I am getting anxious to really start the number-crunching
now... (had to ask two other questions before...).

Thank You all for considerations of my issue! With kind regards,
Björn

sfeam

unread,
Mar 15, 2010, 7:23:08 PM3/15/10
to
bbcda wrote:

> I know that I could set a padding for this using "set offsets", but the
> problem is that this command only allows to give ABSOLUTE values (in
> terms of the axis values) for the room Gnuplot has to leave,

not true



> Instead, I'd like Gnuplot to automatically read the maximum und minimum
> value of the plot range (Gnuplot must have that value internally to
> autoscale the yaxis anyways, I believe...), and then tell him to leave
> e.g. 10 % of room to both sides (top and bottom).

set offset graph 0.10, 0.10

sfeam

unread,
Mar 15, 2010, 7:36:28 PM3/15/10
to
sfeam wrote:

For all 4 boundaries:
set offset graph 0.1, graph 0.1, graph 0.1, graph 0.1

bbcda

unread,
Mar 15, 2010, 9:38:54 PM3/15/10
to
Hey, sfeam!

On 2010-03-15 19:36:28 -0400, sfeam said:

> set offset graph 0.1, graph 0.1, graph 0.1, graph 0.1

Wow! That was exactly what I needed... Thanks! Can You tell, I am still
at the beginner level of Gnuplot (though I have used it from time to
time at least since 2004...)? And, even though I have tried to get into
the basics of it (I even read parts of the new book about it): I
wouldn't have found that solution myself... hm... :-D So, thank You
again!

And, for the ones who find this post by a search, and just for
reference: the four parameters given to this command give the
boundaries (in units of 1 with respect to the axis length - i.e. "1"
would mean a padding of the full axis) in the following order: left,
right, top, bottom.

Best,
Björn

0 new messages