Mittwoch, 14. September 2011

GNUPlot 001: Postscript postproduction

I generated a graph with gnuplot:
Settings were:

set terminal postscript
set output 'outfile.ps'
set size 0.6,0.6
set xlabel "Reaction Coordinate"
set ylabel "dE[kcal/mol]"
plot 'data.dat' with lines lw 4
set output

If i open this file in preview, the file is oriented 90° counter-clock wise. This can be fixed with 'ps2eps'.
The command I used was:

ps2eps -f -R + -B -l data.eps

Samstag, 3. September 2011

Python 003: Summing specific items of nested lists

Say we're faced with the challenge of summing the last element of a list of nested lists.
An example might be

a=[[2,4,6],
[4,2,5],
[2,5,6]]

where we're interested in the sum of 6+5+6. In Python this can conveniently be done using the reduce/lambda pair of functions:

>>> reduce(lambda x,y: x+y, [i[-1] for i in a])
17
>>>