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

finding maximum value in a data set and subtracting from plot

4,464 views
Skip to first unread message

s0198362

unread,
Apr 23, 2010, 12:44:37 PM4/23/10
to
Hi I want to plot a data set, but have it offset (in y) by it's
maximum value

i.e. in the third plot I have a value at offset. Is there a way of
getting gnuplot to look at the data first, determine the maximum
value, then subtract it from my data? This would make the difference
curve sit below my data, rather than ontop of my data.


offset=???
plot pattern u (f($1)):2 t "Observed" with points 1,\
"" u (f($1)):3 t "Calculated" with lines lt rgb "blue",\
"" u (f($1)):(($4)-offset) t "Difference" w lines lt rgb "magenta"

I have tried using multiplot with this, but can't work out how to have
the y axis continuous over both plots without having to fiddle
manually with the plot ranges etc.

Thanks again.

Adrian

Karl

unread,
Apr 24, 2010, 12:52:12 PM4/24/10
to
s0198362 schrieb:

> i.e. in the third plot I have a value at offset. Is there a way of
> getting gnuplot to look at the data first, determine the maximum
> value, then subtract it from my data? This would make the difference
> curve sit below my data, rather than ontop of my data.

After plotting your data for the first time, there is a variable named
GPVAL_DATA_Y_MAX, which holds what you´d expect from its name.

Karl

s0198362

unread,
Apr 25, 2010, 3:50:03 AM4/25/10
to

Hi Karl,

I thought of that possibility. However I would then have to plot the
line twice. Once to get the maximum, then oncae again to plot it with
the offset. Is there a way to "draw" the line but not have it show on
the plot?

Karl

unread,
Apr 25, 2010, 6:35:20 AM4/25/10
to
s0198362 wrote:
> I thought of that possibility. However I would then have to plot the
> line twice. Once to get the maximum, then oncae again to plot it with
> the offset. Is there a way to "draw" the line but not have it show on
> the plot?

plot pattern u 1:4
offset=GPVAL_DATA_Y_MAX
plot "" u 1:($4-offset)

praveen

unread,
Apr 26, 2010, 4:13:46 AM4/26/10
to

Hey Karl,

This works nice. Is there any possibility to see what is the max.
value in our data...!

Thank U.

Ingo Thies

unread,
Apr 26, 2010, 4:27:06 AM4/26/10
to
praveen wrote:

> This works nice. Is there any possibility to see what is the max.
> value in our data...!

Hmm, what about something like

print 'Maximum = ',GPVAL_DATA_Y_MAX

to write the number to the screen?

Ingo

praveen

unread,
Apr 26, 2010, 4:33:27 AM4/26/10
to

Ingo, thank u very much for ur quick reply.
Its helpful.

praveen

unread,
Apr 28, 2010, 4:40:43 AM4/28/10
to
Hi everyone...

Need help in saving data from plotted graph...!
I've shifted my curve by subtracting some constant value from the
data.
I wonder, is there a way to save that altered data into a file from
gnuplot...?

Thank U

Praveen.

Ingo Thies

unread,
Apr 28, 2010, 4:57:05 AM4/28/10
to
praveen wrote:

> I wonder, is there a way to save that altered data into a file from
> gnuplot...?

help table

The table mode allows to write the data into a new data file instead of
plotting it to the screen.

Ingo

praveen

unread,
Apr 28, 2010, 6:35:21 AM4/28/10
to
Thank U Ingo....it works....but in the output file... one more extra
column comes with the letter 'i'.
Can u tell me how can I remove that column and have only the data in
the file...!!

thank u once again.

Praveen.

Ingo Thies

unread,
Apr 28, 2010, 7:15:17 AM4/28/10
to
praveen wrote:
> Thank U Ingo....it works....but in the output file... one more extra
> column comes with the letter 'i'.

This letter indicates whether the written data is (i)nside or (o)utside
the active range, or even (u)ndefined. I don't know whether you can
prevent gnuplot from writing this letter. I'd suggest to simply ignore
it. Or to remove it via a search and replace function of any editor
(replace by blank) or via awk.

Ingo

praveen

unread,
Apr 28, 2010, 10:53:08 AM4/28/10
to

Hi Ingo....I did the same....Is there a way to increase the precision
to 6 digits or even more......of the written data using the command
'table',
Moreover...now I get the error msg... "Bad value during floating point
read".... I've cross checked the data format & the variable data
types...those are perfect.

Please have a look:

integer,parameter:: lmax=10000
real*8 :: mjd(lmax),Bzm(lmax)
.....
.....
.....
read(87,121,END=6666)mjd(j),Bzm(j)
121 format(f8.3,1x,f8.3)

The data is like this:
 465.000 -70.8092
465.001 -70.9246
465.001 -71.1206
465.002 -71.334
465.003 -71.4319
465.003 -71.6977
465.004 -71.3864
465.005 -71.3514
465.006 -71.9217
465.756 -65.8126
465.757 -65.9046
465.758 -65.922
465.758 -65.957
465.759 -66.02

Please let me know is there any error in my code.

Thank U.

Praveen.

Ingo Thies

unread,
Apr 28, 2010, 12:26:04 PM4/28/10
to
praveen wrote:
>
> Hi Ingo....I did the same....Is there a way to increase the precision
> to 6 digits or even more......of the written data using the command
> 'table',

Yes, you can set the output format via the 'set format' command (the
same used for the tic labels, so be aware of surprising appearance of
the plot if you forget to decrease the number of decimals after
unsetting the table mode).

Try

set format '%.16f'

or

set format '%24.16f'

which should be suffieciently accurate (actually, the syntax is similar
but still different from the C format syntax. See 'help format' in
gnuplot for more info).

BTW I am not completely sure from quick & dirty testing whether Gnuplot
actually does double precision or single precision or some special kind
on output. It not double it won't make sense to provide more digits than
actually covered by gnuplot's table output accuracy.

But I can make some tests on that...

> read(87,121,END=6666)mjd(j),Bzm(j)
> 121 format(f8.3,1x,f8.3)
>
> The data is like this:
>  465.000 -70.8092

Maybe, the total number of digits does not fully match the data file. I
would try reading without a specific format, e.g.

read(87,*,END=6666) jd(j),Bzm(j)

and use format specification for output only. If unformatted, Fortran
just reads two numbers that match the variable type (floating point
here) and are separated by spaces or tabs.

Ingo

praveen

unread,
Apr 29, 2010, 11:32:57 AM4/29/10
to

Hi Ingo,

I've solved the case.... the thing is...gnuplot is saving the data and
leaves a special character like: <feef> ...something like that....at
the beginning of the file. This is not visible in some editors...Im
using 'gedit' and its not able to recognize this. But when I tried to
save the data through vi-editor...it comes up. Bcz of this character
in the input file, I was not able to read the data.

Thank U very much for your quick replies and concern.

0 new messages