Donnerstag, 12. Dezember 2013

Bash combining files

Combine files side by side columnwise:

If you have two files one of them consisting of one column and another file consisting of one column as well you can join the files by using:
paste file1 file2

Combine files one after the other:

Simply use:
cat file1 file2
which will first print file1 and then file2.

The "join" command:

Additionally there is also the join command which will print data which is present in file1 and file2, e.g.:
join file1 file2
If file1 and file2 share the same string in one line it gets printed to standard out.

Mittwoch, 11. Dezember 2013

Gnuplot set linecolor from palette

In gnuplot you can set the color of a line in a plot by using:
 linecolor "COLOR" 

For example via, (linecolor is abbreviated via lc):
 plot sin(x) lc "blue"

But there are several others, including setting the linecolor from a palette, so according to the blog entry here and here. You set up a new color macro scheme and use it as a palette. This color palette you can then use to define the color of a line by using either the color of a colorbox (cb) value or a fractional value ranging from 0 to 1:
set palette @redgreenblue
plot sin(x) lc palette cb 1 
replot sin(x) lc palette frac 0.5 


More information can be found in gnuplot via:
help linecolor

Gnuplot user-defined color schemes

As already explained in this blog entry, this is the way to define color macros:
set macros
redgreenblue_small = "defined (\
                   0  0.0 0.0 0.5, \
                   1  0.0 0.0 1.0, \
                   2  0.0 0.5 1.0, \
                   3  0.0 1.0 1.0, \
                   4  0.5 1.0 0.5, \
                   5  1.0 1.0 0.0, \
                   6  1.0 0.5 0.0, \
                   7  1.0 0.0 0.0, \
                   8  0.75 0.0 0.0, \
                   9  0.5 0.0 0.0, \
                   10  0.25 0.0 0.0, \
                   11  0.0 0.0 0.0 )"

To use them in gnuplot you simply type:
set palette @redgreenblue


Periodically execute program (bash) - watch

To periodically execute a command, e.g. ll to see the change in files just use watch:
watch  [-n <seconds>] [--differences[=cumulative]] [--interval=<seconds>] <command>
For example like this:
 watch ls -l

Montag, 9. Dezember 2013

Gnuplot write in a variable from bash

If you want to read in a variable, which is in a file for example or you simply have a script to calculate it into gnuplot. Simply use the following command:

 variable="`BASH COMMAND`"

instead of BASH COMMAND you can use any bash command you like and even load variables or get data from files, e.g.:

 variable="`echo $VARIABLE`"

Dienstag, 3. Dezember 2013

Gnuplot multiplot - problems with replot

All those who use gnuplot multiplot probably know about the problems using replot in the multiplot environment. When using replot the lines which were plotted first and get replotted and appear darker or broader and if the xranges and yranges do not fit perfectly the plots get shifted.


For all that a small
 clear
statement in between the plot and replot might help.


For this i will show a full example in the following and two images of the two results with the png-terminal:
set terminal png
set output "test.png"
set multiplot

plot sin(x)
clear
replot cos(x)

unset multiplot 


without clearwith clear