Gnuplot: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Reference == * [http://www.bersch.net/gnuplot-doc/gnuplot.html gnuplot documentation]. * [http://gnuplot.sourceforge.net/docs_4.2/node100.html#1861 <code>plot</code> comman...") |
|||
Line 20: | Line 20: | ||
== Examples == |
== Examples == |
||
=== Plot XY graphs === |
|||
If given file contains two columns, ''gnuplot'' assumes |
|||
<source lang="text"> |
|||
for ((i=0;i<5000;i++)); do echo $(( $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 line blue" |
|||
</source> |
|||
All in one line: |
|||
<source lang="text"> |
|||
for ((i=0;i<5000;i++)); do echo $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' | gnuplot -p -e "plot '-' with line blue" |
|||
</source> |
|||
=== Plot from stdin === |
=== Plot from stdin === |
||
<source lang="text"> |
<source lang="text"> |
Revision as of 07:40, 27 June 2018
Reference
- 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<5000;i++)); do echo $(( $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 line blue"
All in one line:
for ((i=0;i<5000;i++)); do echo $(( $RANDOM % 256 )); done | sort -n | uniq -c | awk '{print $2 " " $1}' | gnuplot -p -e "plot '-' with line blue"
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