28
Graphical Analysis with Gnuplot Evangelos Pournaras, Izabela Moise, Dirk Helbing Evangelos Pournaras, Izabela Moise, Dirk Helbing 1

Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Graphical Analysis with GnuplotEvangelos Pournaras, Izabela Moise, Dirk Helbing

Evangelos Pournaras, Izabela Moise, Dirk Helbing 1

Page 2: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Outline

1. Introduction to gnuplot

2. Gnuplot in practice

3. Plot examples

4. Output and terminals

Evangelos Pournaras, Izabela Moise, Dirk Helbing 2

Page 3: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Introduction to Gnuplot

Evangelos Pournaras, Izabela Moise, Dirk Helbing 3

Page 4: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Graphical Analysis

• The art of discovering relationships in data & extractinginformation from it by visual means

• Gnuplot: the state-of-the-art tool for graphical analysis

Evangelos Pournaras, Izabela Moise, Dirk Helbing 4

Page 5: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

About Gnuplot

A command-line open-source program for graphically exploring,plotting and visualizing data.

• Thomas Williams, Colin Kelley 1986

• Gnuplot is not GNU & not released under a GPL license

• Gnuplot solves data analysis problems with graphical methods

• Graphs quality: Polished (publications) or simple (exploratory)

Available in all platforms!

TipInstall the wxwidgets variant. It contains the powerful terminal wxt.

(More about terminals later on)

Evangelos Pournaras, Izabela Moise, Dirk Helbing 5

Page 6: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

How it works

• Iterative process of graphical analysis via thecommand-line:

– Issue commands at prompt & gnuplot redraws the plot– Output is generated and displayed immediately– Still can be used in batch-mode

• Do not get scared with the command line!– Very easy to use! Does not require programming skills!

Evangelos Pournaras, Izabela Moise, Dirk Helbing 6

Page 7: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Why Gnuplot

• Stable, mature and actively maintained

• Free and open source - available to all platforms

• Highly customized visualizations - you can control everything

• Supports all common graphics formats

• Reads input text formats and tolerates inconsistent formatting

• Highly scalable - Supports millions of data points

• Requires limited resources

However, gnuplot is neither a statistical program nor a drawing tool!

Evangelos Pournaras, Izabela Moise, Dirk Helbing 7

Page 8: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Gnuplot in Practice

Evangelos Pournaras, Izabela Moise, Dirk Helbing 8

Page 9: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Runtime I• Starting and exiting gnuplot:

>gnuplot>exit

• Choosing the terminal:>set terminal wxt enhanced

• Issue commands:1. Directly at the command line or2. Load a gnuplot script at the command line:

>load "script.gp"• Gnuplot scripts development:

1. Write at a text file and issue:>load "script.gp"

2. Write at the command line and issue:>save "script.gp"

Evangelos Pournaras, Izabela Moise, Dirk Helbing 9

Page 10: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Runtime II

• Accessing and plotting data:

>plot "data.txt"

• Resetting all options to system defaults:

>reset

• Clears the current output device"

>clear

Evangelos Pournaras, Izabela Moise, Dirk Helbing 10

Page 11: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Selecting Data

• Selecting columns:

>plot "data.txt" using 1>plot "data.txt" using 1:3>plot "data.txt" using 1, "data.txt" using 3, ...

• You can add comments directly in your data with ’#’– Gnuplot ingores these lines

• You can choose the field separator:

>set datafile separator ","• Mulptiple data blocks in one file:

– Seperation with two blank lines– Accessing specific blocks:

>plot "data.txt" index 0:1 using 1

Evangelos Pournaras, Izabela Moise, Dirk Helbing 11

Page 12: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Controlling the AppearanceTest plot styles: dots, points, lines, linespoints, impulses

>plot sin(x) with style

>set title "My cool plot">set style line 1 lt 2 lw 2 pt 3 ps 0.5>set xlabel "My X axis">set xlabel "My Y axis">set xtics 1,20,100>set xrange [1:100]>set yrange [1:100]>set key top right>set size square>replot

Evangelos Pournaras, Izabela Moise, Dirk Helbing 12

Page 13: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Operators, Constants & FunctionsPerforming on-the-fly operations on the data:

>plot "data.txt" using (sqrt($1))>plot "data.txt" using (sqrt($1/100))

Plotting functions and defining variables:

>plot sin(x)>set xrange [0:250]>plot sin(x)*(x**2)>a=10>show variables>plot sin(a*x)*(x**2)

Evangelos Pournaras, Izabela Moise, Dirk Helbing 13

Page 14: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Plot Examples

Evangelos Pournaras, Izabela Moise, Dirk Helbing 14

Page 15: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Demos

Demos in gnuplot homepage:http://gnuplot.sourceforge.net/demo_cvs/

• Simple plots: http://gnuplot.sourceforge.net/demo_cvs/simple.html

• Error bars: http://gnuplot.sourceforge.net/demo_cvs/mgr.html

• Histograms: http://gnuplot.sourceforge.net/demo_cvs/histograms.html

• Multi-axis: http://gnuplot.sourceforge.net/demo_cvs/multiaxis.html

• 3-D palette-mapped: http://gnuplot.sourceforge.net/demo_cvs/pm3d.html

• Cool "bars": http://gnuplot.sourceforge.net/demo_cvs/barchart_art.html

• Gantt charts: http://gnuplot.sourceforge.net/demo_cvs/gantt.html

• Heat maps: http://gnuplot.sourceforge.net/demo_cvs/heatmaps.html

Evangelos Pournaras, Izabela Moise, Dirk Helbing 15

Page 16: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Output and Terminals

Evangelos Pournaras, Izabela Moise, Dirk Helbing 16

Page 17: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Output and Terminals

Gnuplot supports more than 70 terminals!

>set terminal

Terminals are classified into 3 categories based on their output:

1. Standard graphics file format, e.g. GIF, JPG, PNG, SVG

2. Output for print, e.g. PostScript and PDF

3. Terminals for interactive use

Evangelos Pournaras, Izabela Moise, Dirk Helbing 17

Page 18: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Saving to PNGA script "export.gp" to export a plot to a PNG file:

save "myplot.gp"set terminal pushset terminal pngset output "output.png"replotset outputset terminal pop

Calling the script:

>call "export.gp"

Evangelos Pournaras, Izabela Moise, Dirk Helbing 18

Page 19: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Saving to Standard GraphicsA more generic script:

>save ARG1.".gp">set terminal push>set terminal ARG2>set output ARG1.".".ARG3>replot>set output>set terminal pop

Calling the script:

>call "export.gp" "myplot" "pdfcairo" "pdf"

Evangelos Pournaras, Izabela Moise, Dirk Helbing 19

Page 20: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Gnuplot and Latex I

You can output plots in LATEX in at least four different ways:

• Output EPS files and use in a LATEXdocument

>set terminal postscript eps enhanced>set output "output.eps">replot

Evangelos Pournaras, Izabela Moise, Dirk Helbing 20

Page 21: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Gnuplot and Latex II

• Output PDF files and use in a LATEX document

>set terminal pdfcairo enhanced>set output "output.pdf">replot

Evangelos Pournaras, Izabela Moise, Dirk Helbing 21

Page 22: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Gnuplot and Latex III

• Use of the epslatex terminal and the \input{output.tex}LATEX command:

>set ylabel ’$\sigma$’>set terminal epslatex>set output "output.tex">replot

Evangelos Pournaras, Izabela Moise, Dirk Helbing 22

Page 23: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Gnuplot and Latex IV

• Use of the gnuplottex package

\usepackage{gnuplottex}...\begin{figure}[htbp]\centering\begin{gnuplot}[terminal=pdf]load "myscript.gp"\end{gnuplot}\end{figure}

Evangelos Pournaras, Izabela Moise, Dirk Helbing 23

Page 24: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Interactive Terminals

• wxt– In wxWidgets. Uses Cairo & Pango libs for graphics & text– Cross-platform– High-quality graphics (anti-aliasing)– Interactive menus

• x11 Unix terminal

• Aqua MacOS terminal

• windows Microsoft Windows terminal

• Many other, e.g. check dumb terminal :)

Evangelos Pournaras, Izabela Moise, Dirk Helbing 24

Page 25: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Comparing Terminal Appearance

Use the test command:������������������

�������������������������������

��������������������

������������������������

����������������������

�����������

��������������������������

��������������

���������������������

�������������������

�������������������

������������� ������������

��������������������������������

������������������������������������

���������

������������� �� �� �� �� �� �� �� ��

���������������

Evangelos Pournaras, Izabela Moise, Dirk Helbing 25

Page 26: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Things to Remember

• Plot size vs canvas size

• Terminals handle the fonts, not gnuplot! e.g.:

>set terminal wxt font ’Verdana, 20’

• Enhanced option:

>set terminal wxt enhanced

– Provides more appearance options– E.g. use of Greek letters, subscripts and superscripts– http://gnuplot.sourceforge.net/demo_cvs/enhanced_

utf8.html

Evangelos Pournaras, Izabela Moise, Dirk Helbing 26

Page 27: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

Proposed Literature

P. K. Janert.Gnuplot in Action: Understanding Data with Graphs.Manning Publications Co., Greenwich, CT, USA, 2009.

But also check the latest documentation:http://www.gnuplot.info/docs_5.0/gnuplot.pdf

Evangelos Pournaras, Izabela Moise, Dirk Helbing 27

Page 28: Graphical Analysis with Gnuplot - ETH Zürich · 2015. 4. 14. · plotting and visualizing data. Thomas Williams, Colin Kelley 1986 Gnuplot is not GNU & not released under a GPL license

What is next?

• Machine learning and data mining

Evangelos Pournaras, Izabela Moise, Dirk Helbing 28