Ein sehr kurzes Gnuplot - Tutorial


  1. Basics
  2. Funktionen plotten
  3. Bezeichnungen, Linientypen
  4. 2d - Datenfile
  5. 2d - Datenfile, mehrere Graphen
  6. 2d - Datenfile, mehrere Datensätze
  7. 3d - Datenfile
  8. Ausgabe in Datei

Basics

  • gnuplot home base: www.gnuplot.info
  • ist in fast jeder Linux-Distribution enthalten (aber vielleicht nicht installiert)
  • Windows - Binaries im Netz
  • Bedienung über Kommandozeile (hier beschrieben)
  • Es gibt auch grafische Frontends für Gnuplot.
  • wird beendet mit Kommando quit
  • vieles kann abgekürzt werden ( q statt quit, w l statt with lines, ...)

    Hilfe

    In Gnuplot erhält man Hilfe durch help, auch mit Kommandonamen als Argument: help plot

    Funktionen plotten

    Sinus
    plot sin(x)

    plot sin(x)


    Sinus im Intervall [-1,7]
    plot[-1:7] sin(x)

    plot[-1:7] sin(x)


    Sinus im Intervall [-1,7], Y im Intervall [-1,1.5]
    plot[-1:7][-1:1.5] sin(x)

    plot[-1:7][-1:1.5] sin(x)


    Mehrere Funktionen zugleich
    plot[-1:7] sin(x), cos(x), sin(x)*cos(x)

    plot[-1:7] sin(x), cos(x), sin(x)*cos(x)


    Bezeichnungen, Linientypen

    Bildtitel
    set title "Sinus und Kosinus"; plot sin(x), cos(x)

    set title


    Achsen beschriften
    set xlabel "IICCKKSS"; set ylabel "IPSILON"; plot sin(x), cos(x)

    set xlabel


    Legende
    plot sin(x) title "Der Sinus", cos(x) t "Der Kosinus"

    plot sin(x) title


    Verschiedene Linientypen
    plot sin(x), sin(x+.5) linetype 2, sin(x+1) linetype 3, sin(x+1.5) linetype 4, sin(x+2) linetype 5

    plot sin(x), sin(x+.5) linetype 2, sin(x+1) linetype 3, sin(x+1.5) linetype 4, sin(x+2) linetype 5


    Anzeige der verschiedenen Typen, Farben, Schriften ...
    test

    test


    2d - Datenfile

    Kommentare ...
    ... beginnen mit einem Doppelkreuz #

    Daten (d1.dat)
    #
    # x sin(x)
    # h=0.25 * pi
    0 0
    .785398 .707106
    1.570796 1.000000
    2.356194 .707107
    3.141592 0

    Mit Punkten (Standard)
    plot 'd1.dat'

    plot 'd1.dat'


    Mit Linien
    plot 'd1.dat' with lines

    plot 'd1.dat' with lines


    Mit Linien und Punkten
    plot 'd1.dat' w lp

    plot 'd1.dat' w lp


    Zwei Dateien mit verschiedenen Linientypen
    plot 'd1.dat' w l linetype 3, 'd1a.dat' w lp lt 4

    plot 'd1.dat' w l linetype 3, 'd1a.dat' w lp lt 4


    2d - Datenfile, mehrere Graphen

    Werte verschiedener Funktionen/Verfahren ...
    • ... werden durch Leerzeichen getrennt zeilenweise gespeichert
    • Nummerierung beginnt bei 1
    • Leerer Dateiname '' wiederholt vorangegangenen Namen
    Daten (d2.dat)
    #
    # x sin(x) cos(x)
    # h=0.25 * pi
    0 0 1.000000
    .785398 .707106 .707106
    1.570796 1.000000 0
    2.356194 .707107 -.707106
    3.141592 0 -1.000000

    X-Achse: 1. Spalte, Y-Achse: 2.Spalte (Erste Funktion)
    plot 'd2.dat' with lines

    plot 'd2.dat' with  lines


    X-Achse: 1. Spalte, Y-Achse: 3.Spalte (Zweite Funktion)
    plot 'd2.dat' using 1:3 w l

    plot 'd2.dat' using 1:3 w l


    X-Achse: 2. Spalte, Y-Achse: 3.Spalte
    plot 'd2.dat' using 2:3 w l

    plot 'd2.dat' using 2:3 w l


    X-Achse: 3. Spalte, Y-Achse: 1.Spalte
    plot 'd2.dat' u 3:1 w l

    plot 'd2.dat' u 3:1 w l


    Beide Funktionen
    plot 'd2.dat' w l, '' using 1:3 w l

    plot 'd2.dat' w l, ''  using 1:3 w l


    y-Werte beider Funktionen über Nummer
    plot 'd2.dat' u :2 w l, '' using :3 w l

    plot 'd2.dat' u :2 w l, ''  using :3 w l


    2d - Datenfile, mehrere Datensätze

    2 Leerzeilen in einem Datenfile
    • ... trennen Datensätze
    • Erster Datensatz heisst "0", zweiter ist "1" usw.
    Daten (d2-2.dat)
    #
    # x sin(x) cos(x)
    # h=0.25 * pi
    0 0 1.000000
    .785398 .707106 .707106
    1.570796 1.000000 0
    2.356194 .707107 -.707106
    3.141592 0 -1.000000


    # x sin(x) cos(x)
    # h=0.1 * pi
    0 0 1.000000
    .314159 .309016 .951056
    .628318 .587784 .809017
    .942477 .809016 .587785
    1.256636 .951056 .309018
    1.570796 1.000000 0
    1.884955 .951056 -.309016
    2.199114 .809017 -.587784
    2.513273 .587786 -.809016
    2.827432 .309018 -.951056
    3.141592 0 -1.000000

    Erster Datensatz mit Punkten (Standard)
    plot 'd2m.dat' index 0

    plot 'd2m.dat' index 0


    Zweiter mit Linien
    plot 'd2m.dat' index 1 with lines

    plot 'd2m.dat' index 1 with lines


    Beide in verschiedenen Stilen
    plot 'd2m.dat' i 0 w l lt 3, '' i 1 w lp lt 5

     plot 'd2m.dat' i 0 w l lt 3, '' i 1 w lp lt 5


    3d - Datenfile

    Die ersten 3 Spalten ...
    ... werden als x-, y- und z- Werte interpretiert
    Daten (d2.dat)
    wie oben unter 2d - Datenfile, mehrere Graphen

    3d - Grafik mit splot (Surface - plot)
    splot 'd2.dat' with linespoints

    splot 'd2.dat' with linespoints


    Vertauschung der Koordinaten mittels using
    splot 'd2.dat' using 2:3:1 w lp

    splot 'd2.dat' using 2:3:1 w lp


    Interessantere Daten (d3.dat) ..
    .. gibts HIER
    3d - Grafik mit splot (Surface - plot)
    splot 'd3.dat' with lines, '' with points linetype 3

    splot 'd3.dat' with lines, '' with points linetype 3


    Vertauschung der Koordinaten mittels using
    splot 'd3.dat' using 2:3:1 w l, '' u 2:3:1 w p lt 3

    splot 'd3.dat' using 2:3:1 w l, '' u 2:3:1 w p lt 3


    Ausgabe in Datei

    Verschiedene Ausgabeformate ...
    • set term xxx setzt Ausgabeformat auf Typ xxx
    • Liste mit set term
    • Hilfe mit help set term
    • Für die Übungen benutzen Sie am besten PNG (Portabel Network Graphics), also: set term png
    • Nützlich (funktioniert aber NICHT als Stack!!) :
      • set term push speichert aktuelle Einstellung
      • set term pop stellt gespeicherte Einstellung wieder her
    Festlegen der Zieldatei
    • set output "meinbild.png" legt fest, dass das nächste plot-Kommando in Datei "meinbild.png" schreibt
    • Wenn mehrere plot-Befehle in ein und dieselbe Datei schreiben, so ist mest nur erste plot sichtbar (es sei denn, das gewählte Format unterstützt mehrere Seiten)
    • Also immer ein plot pro set output
    • Beenden der Ausgabe in Datei: set output (Ohne Dateinamen)
    Beispielsitzung:
  • splot 'd3.dat' w l, '' w p lt 3
    set term png
    set output 'meinbild.png'
    replot
    set term postscript eps
    set output 'meinbild.eps'
    replot
    unset output
    set term pop
    set view 70,20,1
    replot
    set view 85,135,1
    replot
    set term png
    set output 'meinbild2.png'
    replot
    quit
    Daten auf Bildschirm plotten
    Ausgabe als PNG-Bild wählen
    Bild soll in meinbild.png geschrieben werden
    Letzten Plot wiederholen, Datei wird erzeugt
    Auch noch als EPS
    Datei setzen
    Plot in Datei als EPS-Grafik
    Ausgabe in Datei abschalten
    Ausgabeformat auf Standard zurük
    Anderen Blickwinkel setzen
    Plotten mit neuen Blickwinkel
    Anderen Blickwinkel setzen
    Testen
    PNG - Format wählen
    Datei wählen
    Plotten
    Ende

    mailto