[pgfplots]: Bereich zwischen zwei Funktionen füllen

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: [pgfplots]: Bereich zwischen zwei Funktionen füllen

von Bartman » Do 10. Mai 2018, 06:20

\begin{filecontents}{Daten.dat}
0.000000        3.950000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
4.000000        3.950000        1.128345        -0.005761       0.026303        1.107803        1.011839        -0.005229       0.023874        0.993194
3.900000        3.850000        0.825854        -0.005761       0.024954        0.806662        0.735524        -0.005229       0.022649        0.718103
3.800000        3.500000        0.251117        -0.005761       0.020233        0.236645        0.220355        -0.005229       0.018364        0.207220
3.200000        2.900000        -0.246292       -0.005761       0.012140        -0.252670       -0.219329       -0.005229       0.011019        -0.225119
2.600000        2.300000        -0.323851       -0.005761       0.004047        -0.322136       -0.287514       -0.005229       0.003673        -0.285958
2.000000        1.700000        -0.329464       -0.005761       -0.004047       -0.319657       -0.292415       -0.005229       -0.003673       -0.283513
1.400000        1.100000        -0.265048       -0.005761       -0.012140       -0.247147       -0.235672       -0.005229       -0.011019       -0.219424
0.800000        0.500000        0.229870        -0.005761       -0.020233       0.255863        0.200523        -0.005229       -0.018364       0.224116
0.200000        0.150000        0.767236        -0.005761       -0.024954       0.797951        0.681352        -0.005229       -0.022649       0.709231
0.100000        0.050000        0.940158        -0.005761       -0.026303       0.972221        0.840694        -0.005229       -0.023874       0.869797
0.000000        0.050000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
0.000000        3.950000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
4.000000        3.950000        4.692340        -0.012513       1.498949        3.205903        3.576882        -0.008948       1.238629        2.347200
3.900000        3.850000        4.782936        -0.012513       1.422080        3.373368        3.638017        -0.008948       1.175109        2.471856
3.800000        3.500000        2.838887        -0.012513       1.153038        1.698362        2.125413        -0.008948       0.952791        1.181569
3.200000        2.900000        -0.348882       -0.012513       0.691823        -1.028192       -0.236806       -0.008948       0.571675        -0.799533
2.600000        2.300000        -1.909953       -0.012513       0.230608        -2.128048       -1.383152       -0.008948       0.190558        -1.564763
2.000000        1.700000        -2.121673       -0.012513       -0.230608       -1.878553       -1.543266       -0.008948       -0.190558       -1.343760
1.400000        1.100000        -1.301342       -0.012513       -0.691823       -0.597006       -0.986874       -0.008948       -0.571675       -0.406252
0.800000        0.500000        0.234402        -0.012513       -1.153038       1.399952        0.005122        -0.008948       -0.952791       0.966861
0.200000        0.150000        0.946484        -0.012513       -1.422080       2.381077        0.528038        -0.008948       -1.175109       1.712095
0.100000        0.050000        0.558564        -0.012513       -1.498949       2.070025        0.197693        -0.008948       -1.238629       1.445269
0.000000        0.050000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000 
\end{filecontents}

\documentclass[border=5pt]{standalone}

\usepackage{selinput}% https://texwelt.de/wissen/fragen/5546
\SelectInputMappings{
	adieresis={ä},
	germandbls={ß}
}
\usepackage[T1]{fontenc}                     
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepackage{siunitx}% Ersatz für units
\usepackage{xfrac}% für \sfrac

\usetikzlibrary{matrix}
\usepgfplotslibrary{fillbetween}

% Für das Beispiel wurde die Version 1.16 benutzt. 
% Näheres unter https://texwelt.de/wissen/fragen/19163
\pgfplotsset{compat=newest}

\sisetup{
	locale=DE, 
	per-mode=fraction,
	fraction-function=\sfrac
}
 
\begin{document} 
\begin{tikzpicture}
\begin{axis}[
	height=5.5cm,
	width=4.3cm,
	grid,
	xmin=-5,
	xmax=5,
	ymin=0,
	ymax=4,
	y tick label style={
		/pgf/number format/.cd,
			fixed,
			fixed zerofill,
			precision=0,
		/tikz/.cd
	},
	xlabel={\si{\N\per\mm\squared}},
	ylabel={Höhe in \si{\m}}
] 
\draw [thin] (axis cs:0,-1) -- (axis cs:0,5);

\addplot [
	thick, 
	skip coords between index={13}{1000}, 
	name path=A
] table [
	x expr={\thisrowno{2}/1},
	y index=1, 
	skip first n=11
] {Daten.dat};

\addplot [
	thick, 
	dashed, 
	skip coords between index={13}{1000}, 
	name path=B
] table [
	x expr={\thisrowno{6}/1},
	y index=1, 
	skip first n=11
] {Daten.dat};

\draw [thin, dashdotted] (axis cs:2.528*0.7,-1) -- (axis cs:2.528*0.7,5);
\draw [red, thin, dashdotted] (axis cs:2.928*0.7,-1) -- (axis cs:2.928*0.7,5);

\draw [
	green, 
	thin, 
	dashdotted, 
	name path=C
] (axis cs:2.716*0.7,-1) -- (axis cs:2.716*0.7,5); 

\addplot [fill=none] fill between [
	of=A and C, 
	split, 
	every segment no 1/.style={fill=gray}
];
\end{axis}    
\end{tikzpicture} 
\end{document}

[pgfplots]: Bereich zwischen zwei Funktionen füllen

von jens1988 » Mi 9. Mai 2018, 10:59

Hallo liebe Forianer,

ich stehe vor einem Problem. Irgendwie bekomme ich es nicht hin einen Bereich in pgfplots zu füllen, der von zwei Funktionen ("Funktion" stimmt nicht ganz, es sind Datenpunkte aus einer Datentabelle) begrenzt wird.

Minimalbeispiel:
\documentclass[
a4paper,         
BCOR20mm,        
numbers=noenddot, 
oneside,          
parskip=half,    
openright,        
fleqn,
bibtotoc          
]{scrreprt}
		
\usepackage[ngerman]{babel}	
\usepackage[ansinew]{inputenc}					
\usepackage[T1]{fontenc}							
\usepackage{graphicx} 
\usepackage{pgfplots}
\usepackage{amsmath} 
\usepackage{units}

\usetikzlibrary{matrix}
\usetikzlibrary{external}
\usepgfplotslibrary{external}
\usepgfplotslibrary{fillbetween}
\tikzexternalize
\tikzsetexternalprefix{img_exp/}
 
\begin{document} 
 \chapter{Kapitel 1}
 \section{Section 1}
 \begin{figure}[htbp]
   \centering
   \begin{tikzpicture}
    \pgfplotsset{
      compat=1.10,
      height=5.5cm,
      width=4.3cm,
      grid,
    }
    \begin{axis}[
      xmin=-5,
      xmax=5,
      ymin=0,
      ymax=4,
      y tick label style={
          /pgf/number format/.cd,
              fixed,
              fixed zerofill,
              precision=0,
          /tikz/.cd
      },
      xlabel={$\unitfrac[]{N}{mm^2}$},
      ylabel={Höhe in m},     
    ] 
     \draw[black, thin] (axis cs:0,-1) -- (axis cs:0,5);   
     \addplot[black, thick, solid, skip coords between index={13}{1000}, name path=A] table [x expr={\thisrowno{2}/1},y index=1, skip first n=11] {Daten.dat};
     \addplot[black, thick, dashed, skip coords between index={13}{1000}, name path=B] table [x expr={\thisrowno{6}/1},y index=1, skip first n=11] {Daten.dat};
     \draw[black, thin, dashdotted] (axis cs:2.528*0.7,-1) -- (axis cs:2.528*0.7,5);
     \draw[red, thin, dashdotted] (axis cs:2.928*0.7,-1) -- (axis cs:2.928*0.7,5);
     \draw[green, thin, dashdotted, name path=C] (axis cs:2.716*0.7,-1) -- (axis cs:2.716*0.7,5); 
     \addplot[gray] fill between[of=A and C, domain=2.716*0.7:4];   
    \end{axis}    
   \end{tikzpicture} 
   \caption{Caption 1}
 \end{figure} 
\end{document} 
Datentabelle (Daten.dat):
0.000000        3.950000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
4.000000        3.950000        1.128345        -0.005761       0.026303        1.107803        1.011839        -0.005229       0.023874        0.993194
3.900000        3.850000        0.825854        -0.005761       0.024954        0.806662        0.735524        -0.005229       0.022649        0.718103
3.800000        3.500000        0.251117        -0.005761       0.020233        0.236645        0.220355        -0.005229       0.018364        0.207220
3.200000        2.900000        -0.246292       -0.005761       0.012140        -0.252670       -0.219329       -0.005229       0.011019        -0.225119
2.600000        2.300000        -0.323851       -0.005761       0.004047        -0.322136       -0.287514       -0.005229       0.003673        -0.285958
2.000000        1.700000        -0.329464       -0.005761       -0.004047       -0.319657       -0.292415       -0.005229       -0.003673       -0.283513
1.400000        1.100000        -0.265048       -0.005761       -0.012140       -0.247147       -0.235672       -0.005229       -0.011019       -0.219424
0.800000        0.500000        0.229870        -0.005761       -0.020233       0.255863        0.200523        -0.005229       -0.018364       0.224116
0.200000        0.150000        0.767236        -0.005761       -0.024954       0.797951        0.681352        -0.005229       -0.022649       0.709231
0.100000        0.050000        0.940158        -0.005761       -0.026303       0.972221        0.840694        -0.005229       -0.023874       0.869797
0.000000        0.050000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
0.000000        3.950000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
4.000000        3.950000        4.692340        -0.012513       1.498949        3.205903        3.576882        -0.008948       1.238629        2.347200
3.900000        3.850000        4.782936        -0.012513       1.422080        3.373368        3.638017        -0.008948       1.175109        2.471856
3.800000        3.500000        2.838887        -0.012513       1.153038        1.698362        2.125413        -0.008948       0.952791        1.181569
3.200000        2.900000        -0.348882       -0.012513       0.691823        -1.028192       -0.236806       -0.008948       0.571675        -0.799533
2.600000        2.300000        -1.909953       -0.012513       0.230608        -2.128048       -1.383152       -0.008948       0.190558        -1.564763
2.000000        1.700000        -2.121673       -0.012513       -0.230608       -1.878553       -1.543266       -0.008948       -0.190558       -1.343760
1.400000        1.100000        -1.301342       -0.012513       -0.691823       -0.597006       -0.986874       -0.008948       -0.571675       -0.406252
0.800000        0.500000        0.234402        -0.012513       -1.153038       1.399952        0.005122        -0.008948       -0.952791       0.966861
0.200000        0.150000        0.946484        -0.012513       -1.422080       2.381077        0.528038        -0.008948       -1.175109       1.712095
0.100000        0.050000        0.558564        -0.012513       -1.498949       2.070025        0.197693        -0.008948       -1.238629       1.445269
0.000000        0.050000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000        0.000000
Auffüllen möchte ich den Bereich, der von der grünen strichpunktierten vertikalen Linie und der durchgezogenen schwarzen Linie begrenzt wird und rechts von der grünen strichpunktierten Linie (etwa bei x = 2:4) liegt.

Ich habe das bisher wie sonst auch über definieren eines pathes bzw. anschließendem "fill between" versucht, aber diesmal klappt es nicht und ich komme einfach nicht auf die Lösung.

Ich wäre für jede Hilfe dankbar,
Grüße,
jens1988

Nach oben