Seite 1 von 1

pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 00:09
von ChemSim
Hallo zusammen,

ich habe folgenden Code:
\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.18}

\usepackage{filecontents}
\begin{filecontents}{data1.txt}
x	y
0.0001	3.6448
0.00012	3.64611
0.00014	3.64705
0.00016	3.64799
0.00018	3.64892
0.00021	3.64986
0.00024	3.6508
0.00027	3.65174
0.00031	3.65268
0.00035	3.65362
0.00041	3.6505
0.00046	3.63322
0.00053	3.63415
0.0006	3.63509
0.00069	3.63602
0.00079	3.6168
0.0009	3.59768
0.00103	3.59461
0.00118	3.57561
0.00135	3.54881
0.00154	3.51049
0.00176	3.46679
0.00201	3.41604
0.0023	3.3679
0.00263	3.28922
0.003	3.21237
0.00343	3.13036
0.00392	3.04197
0.00448	2.94133
0.00512	2.8314
0.00586	2.71651
0.00669	2.59761
0.00765	2.46602
0.00874	2.32555
0.00999	2.17728
0.01142	2.00923
0.01306	1.83672
0.01492	1.66415
0.01705	1.4986
0.01949	1.3413
0.02228	1.19121
0.02546	1.05146
0.02893	0.92045
0.03246	0.80267
0.03599	0.69681
0.03943	0.60844
0.04293	0.53057
0.04646	0.46239
0.04997	0.40344
0.05342	0.35056
0.05677	0.30499
0.06032	0.26244
0.06372	0.22582
0.06689	0.19472
0.07022	0.16638
0.07328	0.1431
0.076	0.12459
0.08009	0.10035
\end{filecontents}

\begin{filecontents}{data2.txt}
x	y
0.00039	0.10026
0.00039	3.9916
\end{filecontents}

\begin{document}
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}
        \begin{axis}
        [
        width=13cm, % Breite des Diagramms
        height=8cm, % Höhe des Diagramms
        xmin=1e-4, xmax=1e-1, % Skalierung der x-Achse
        ymin=1e-1, ymax=1e1, % Skalierung der y-Achse
        xlabel=Flüssigkeitsbelastung~$\dot{V}_L A_c^{-1}$ / \unit{\meter\per\second}, % Achsenbeschriftung der x-Achse
        ylabel=Gasbelastung~$\dot{V}_G A_c^{-1}$ / \unit{\meter\per\second}, % Achsenbeschriftung der y-Achse
        xmode=log, % x-Achse logarithmisch
        ymode=log, % x-Achse logarithmisch
        grid=both,
        legend style={
            at={(0.02,0.98)},
            anchor=north west,
            draw=none,
        },
        ]

        \addplot[
        color=blue,
        thick,
        ]
        table
        {data1.txt};

        \addplot[
        color=black,
        thick,
        ]
        table
        {data2.txt};

        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}
Ich würde gerne die Fläche, die sowohl von der blauen Kurve, als auch von der senkrechten schwarzen Linie eingeschlossen ist, mit einer Farbe füllen. Leider habe ich dazu keine Möglichkeit gefunden.

Würde mich über eure Hilfe sehr freuen!

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 08:51
von Rolli
Zunächst mal: Dein Beispiel übersetzt nicht. Benutze siunitx.
Hier - Quick and Dirty:
\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.18}

\usepackage{filecontents}
\usepackage{siunitx}
\begin{filecontents}{data1.txt}
x	y
0.0001	3.6448
0.00012	3.64611
0.00014	3.64705
0.00016	3.64799
0.00018	3.64892
0.00021	3.64986
0.00024	3.6508
0.00027	3.65174
0.00031	3.65268
0.00035	3.65362
0.00041	3.6505
0.00046	3.63322
0.00053	3.63415
0.0006	3.63509
0.00069	3.63602
0.00079	3.6168
0.0009	3.59768
0.00103	3.59461
0.00118	3.57561
0.00135	3.54881
0.00154	3.51049
0.00176	3.46679
0.00201	3.41604
0.0023	3.3679
0.00263	3.28922
0.003	3.21237
0.00343	3.13036
0.00392	3.04197
0.00448	2.94133
0.00512	2.8314
0.00586	2.71651
0.00669	2.59761
0.00765	2.46602
0.00874	2.32555
0.00999	2.17728
0.01142	2.00923
0.01306	1.83672
0.01492	1.66415
0.01705	1.4986
0.01949	1.3413
0.02228	1.19121
0.02546	1.05146
0.02893	0.92045
0.03246	0.80267
0.03599	0.69681
0.03943	0.60844
0.04293	0.53057
0.04646	0.46239
0.04997	0.40344
0.05342	0.35056
0.05677	0.30499
0.06032	0.26244
0.06372	0.22582
0.06689	0.19472
0.07022	0.16638
0.07328	0.1431
0.076	0.12459
0.08009	0.10035
\end{filecontents}

\begin{filecontents}{data1a.txt}
x	y
0.00039	3.65154
0.00041	3.6505
0.00046	3.63322
0.00053	3.63415
0.0006	3.63509
0.00069	3.63602
0.00079	3.6168
0.0009	3.59768
0.00103	3.59461
0.00118	3.57561
0.00135	3.54881
0.00154	3.51049
0.00176	3.46679
0.00201	3.41604
0.0023	3.3679
0.00263	3.28922
0.003	3.21237
0.00343	3.13036
0.00392	3.04197
0.00448	2.94133
0.00512	2.8314
0.00586	2.71651
0.00669	2.59761
0.00765	2.46602
0.00874	2.32555
0.00999	2.17728
0.01142	2.00923
0.01306	1.83672
0.01492	1.66415
0.01705	1.4986
0.01949	1.3413
0.02228	1.19121
0.02546	1.05146
0.02893	0.92045
0.03246	0.80267
0.03599	0.69681
0.03943	0.60844
0.04293	0.53057
0.04646	0.46239
0.04997	0.40344
0.05342	0.35056
0.05677	0.30499
0.06032	0.26244
0.06372	0.22582
0.06689	0.19472
0.07022	0.16638
0.07328	0.1431
0.076	0.12459
0.08009	0.10035
0.00039	0.10026
\end{filecontents}

\begin{filecontents}{data2.txt}
x	y
0.00039	0.10026
0.00039	3.9916
\end{filecontents}

\begin{document}
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}
        \begin{axis}
        [
        width=13cm, % Breite des Diagramms
        height=8cm, % Höhe des Diagramms
        xmin=1e-4, xmax=1e-1, % Skalierung der x-Achse
        ymin=1e-1, ymax=1e1, % Skalierung der y-Achse
        xlabel=Flüssigkeitsbelastung~$\dot{V}_L A_c^{-1}$ / \si{\meter\per\second}, % Achsenbeschriftung der x-Achse
        ylabel=Gasbelastung~$\dot{V}_G A_c^{-1}$ / \si{\meter\per\second}, % Achsenbeschriftung der y-Achse
        xmode=log, % x-Achse logarithmisch
        ymode=log, % x-Achse logarithmisch
        grid=both,
        legend style={
            at={(0.02,0.98)},
            anchor=north west,
            draw=none,
        },
        ]

        \addplot[
        fill=green,
        draw=blue,
        thick,
        ]
        table
        {data1a.txt};

        \addplot[
        color=blue,
        thick,
        ]
        table
        {data1.txt};

        \addplot[
        color=black,
        thick,
        ]
        table
        {data2.txt};

        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}
Gruß vom Rolli

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 09:00
von ChemSim
Hallo Rolli,

danke für deine Antwort. Ach ja stimmt, das siunitx-Paket hatte ich vergessen. Ich kann leider nicht genau nachvollziehen, wie du auf diese Daten in data1a.txt kommst.

Gerne würde ich das Vorgehen für andere Beispiele selbst ausprobieren!

Gruß
ChemSim

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 09:06
von Rolli
Die ersten Punkte x < 0,00039 heraus gelöscht, für 0,00039 den y-Wert linear interpoliert, und am Ende einen Punkt x=0,00039 y=der letzte y-Wert des letzten Punktes hinzu gefügt.
Gruß vom Rolli
P.S.: Geht bestimmt auch eleganter - mit \path und domain usw., wie gesagt Quick-and-Dirty

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 09:13
von ChemSim
Alles klar, danke!

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 09:50
von Stefan Kottwitz
Du kannst Plots Namen geben, zur Achse hin füllen, und mit soft clip durch einen Bereich beschränken, hier mit einem Rechteck:
\path[name path=axis] (0.0001,0.1) -- (0.1,0.1);
\addplot[color=blue!20] fill between[of=data1 and axis,
    soft clip = { (0.00039,0.1) rectangle (0.1,10) }];
Vollständiger Code, nur vertikal bisschen zusammengezogen damit es im Forum einfacher zu lesen ist ohne viel Scrollen, daher auch die Daten zum Online-Compiler kopiert:
\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}
        [
        width=13cm, % Breite des Diagramms
        height=8cm, % Höhe des Diagramms
        xmin=1e-4, xmax=1e-1, % Skalierung der x-Achse
        ymin=1e-1, ymax=1e1, % Skalierung der y-Achse
        xlabel=Flüssigkeitsbelastung~$\dot{V}_L A_c^{-1}$ / \unit{\meter\per\second}, % Achsenbeschriftung der x-Achse
        ylabel=Gasbelastung~$\dot{V}_G A_c^{-1}$ / \unit{\meter\per\second}, % Achsenbeschriftung der y-Achse
        xmode=log, % x-Achse logarithmisch
        ymode=log, % x-Achse logarithmisch
        grid=both,
        legend style={
            at={(0.02,0.98)},
            anchor=north west,
            draw=none,
        }]
        \addplot[color=blue,  thick, name path=data1] table {data1.txt};
        \addplot[color=black, thick] table {data2.txt};

        \path[name path=axis] (0.0001,0.1) -- (0.1,0.1);
        \addplot[color=blue!20] fill between[of=data1 and axis,
           soft clip = { (0.00039,0.1) rectangle (0.1,10) }];

        \end{axis}
    \end{tikzpicture}
\end{document}
plot-gefuellt.png
Stefan

Re: pgfplots: Fläche zwischen zwei Graphen und x-Achse füllen

Verfasst: So 11. Aug 2024, 12:49
von ChemSim
Hallo Stefan,

super, deine Methode gefällt mir noch besser als die vorherige!

Besten Dank und viele Grüße
ChemSim