Gnuplot: Difference between revisions

From miki
Jump to navigation Jump to search
Line 29: Line 29:
# 2 25
# 2 25
# 3 10
# 3 10
gnuplot -p -e "plot 'data' with line blue"
gnuplot -p -e "plot 'data' with lines"
</source>
</source>


All in one line:
All in one line:
<source lang="text">
<source lang="text">
for ((i=0;i<256;i++)); do echo $i $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' | gnuplot -p -e "plot '-' with line blue"
for ((i=0;i<256;i++)); do echo $i $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' | gnuplot -p -e "plot '-' with lines"
</source>
</source>



Revision as of 07:48, 27 June 2018

Reference

Commands

Command-line

gnuplot -p -e 'plot "alacritty-deq-intel.txt" with lines lt rgb "royalblue"'

Plot

plot "urxvt-nvidia.txt" with lines
plot "urxvt-nvidia.txt" with lines lt rgb "orange"
plot "urxvt-nvidia.txt" with lines lt rgb "orange" dashtype 2

Examples

Plot XY graphs

If given file contains two columns, gnuplot assumes

for ((i=0;i<256;i++)); do echo $i $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' > data
head -n 4 data
# 0 20
# 1 18
# 2 25
# 3 10
gnuplot -p -e "plot 'data' with lines"

All in one line:

for ((i=0;i<256;i++)); do echo $i $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' | gnuplot -p -e "plot '-' with lines"

Plot from stdin

primes 1 100 |gnuplot -p -e 'plot "/dev/stdin"'

Heavy-side functions

(x) = ... define your first function
g(x) = ... define your second function
h(x) = (x<0.5)?f(x):g(x)
plot h(x)

To change color:

plot (x<0.5?f(x):1/0) lc 1, (x>0.5?g(x):1/0) lc 2

Plot one or several files

plot "alacritty-deq-intel.txt" with lines lt rgb "royalblue"

To plot several files on the same graph, just separate with a comma ,:

plot "alacritty-deq-intel.txt" with lines lt rgb "royalblue", "alacritty-intel.txt" with lines lt rgb "brown"

Set graph range

set yrange [0:2.5]

Set location of the legend

set key right bottom;

Plot with dash

Use a predefined dashtype:

plot x dashtype 2

We can define custom dashtype [1]:

plot x dashtype (3,5,10,5),\
     2*x dashtype '.-_'

To change the default linetype to dashtype:

set for [i=1:8] linetype i dashtype i

To change the colorset:

set colorsequence default|podo|classi

Output to a file

To generate a .png:

et terminal pngcairo dashed
set output 'test.png'
test
set output

To generate a .eps:

set terminal postscript eps color colortext
set output 'test.eps'
test
set output