Gnuplot: Difference between revisions
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
== Reference == |
== Reference == |
||
* [http://www.gnuplotting.org/ gnuplot official site], with many examples. |
|||
* [http://www.bersch.net/gnuplot-doc/gnuplot.html gnuplot documentation]. |
* [http://www.bersch.net/gnuplot-doc/gnuplot.html gnuplot documentation]. |
||
* [http://gnuplot.sourceforge.net/docs_4.2/node100.html#1861 <code>plot</code> command]. |
* [http://gnuplot.sourceforge.net/docs_4.2/node100.html#1861 <code>plot</code> command]. |
||
Line 29: | Line 30: | ||
# 2 25 |
# 2 25 |
||
# 3 10 |
# 3 10 |
||
gnuplot -p -e "plot 'data' with |
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 |
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> |
||
Latest revision as of 07:54, 27 June 2018
Reference
- gnuplot official site, with many examples.
- gnuplot documentation.
plot
command.- color code for gnuplot (although I remember we could get the list with a command).
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