Seite 1 von 1

Datenimport pgfplots: Mengendifferenz zw. y- und x-Werten

Verfasst: So 7. Dez 2014, 01:08
von malelou
Hallo liebe Forengemeinde,
ich habe folgendes Problem: Ich habe eine Wertetabelle als Textdatei mit einer Spalte x-Werten und mehreren Spalten y-Werten, aus welcher ich nun verschiedene Datenreihen (y1 und y2 über x) in einem Diagramm darstellen möchte. Allerdings hat y2 weniger Werte als y1, sodass der Graph schon früher aufhören sollte. Meinem folgenden Minimalbeispiel folgend wird aber stattdessen der letzte vorhandene y2-Wert über die restlichen x-Werte aufgetragen, sodass sich am Ende ein nicht erwünschtes Plateau ergibt.

Gibt es dafür eine elegante Lösung?

Vielen lieben Dank im Voraus!
\begin{filecontents*}{test.dat}
#  Messwerte   
#  x	y1		y2    
   1	3.5		4.5
   2	3.8		5.2
   3	4.1		6.5
   4	4.5		7.8
   5	5.0
   6	5.8
   7	6.5
\end{filecontents*}

\documentclass[11pt,a4paper]{scrartcl}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}

\begin{axis}
\addplot[color=red]
table [ x index={0},y index={1}]{test.dat};
\addplot[color=green]
table [ x index={0},y index={2}]{test.dat};
\end{axis}

\end{tikzpicture}
\end{document}


Verfasst: So 7. Dez 2014, 10:35
von esdd
Wenn Du von Hand feststellen kannst, bis zu welchem x-Wert die y2-Werte vorhanden sind, dann kannst Du restrict x domain to= <anfangswert>:<endwert> nutzen.
\documentclass{scrartcl} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.10} 

\begin{document} 
\begin{tikzpicture} 
\begin{axis} 
  \addplot[color=red]
    table [ x index={0},y index={1}]{test.dat}; 
  \addplot[color=green] 
    table [ x index={0},y index={2},restrict x to domain=1:4]{test.dat}; 
\end{axis} 
\end{tikzpicture} 
\end{document} 
Gruß
Elke

Verfasst: So 7. Dez 2014, 13:14
von malelou
Toll, vielen Dank! Das hat mein Problem gelöst.