Example: Convergence Plot

Published 2014-03-15 | Author: Christian Feuersänger

We assume that we did some scientfic experiment. The scientific experiment yielded three input data tables: one table for each involved parameter d = 2, d = 3, d = 4. The data tables contain “degrees of freedom” and some accuracy measurement “l2_err”. In addition, they might contain some meta-data (in our case a column “level”).

What we want is to produce three plots, each dof versus l2_err, in a loglog plot. We expect that the result is a line in a loglog plot, and we are interested in its slope log e(N) = -a log(N) because that characterizes our experiment.

The code is from the PGFPlots 1.10 manual: “3.3 Solving a Real Use Case: Scientific Data Analysis”.

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Convergence Plot

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    grid=major,
    legend entries={$d=2$,$d=3$,$d=4$},
]
\addplot table {data_d2.dat};
\addplot table {data_d3.dat};
\addplot table {data_d4.dat};
\addplot table[
     x=dof,
     y={create col/linear regression={y=l2_err,
      variance list={1000,800,600,500,400,200,100}}}]
   {data_d4.dat}
   % save two points on the regression line
   % for drawing the slope triangle
   coordinate [pos=0.25] (A)
   coordinate [pos=0.4]  (B)
   ;
% save the slope parameter:
\xdef\slope{\pgfplotstableregressiona}

% draw the opposite and adjacent sides
% of the triangle
\draw (A) -| (B)
     node [pos=0.75,anchor=west]
         {\pgfmathprintnumber{\slope}};
\end{loglogaxis}
\begin{loglogaxis}[
        footnotesize,
        clip=false,
        xshift=7cm,
]
\addplot table {data_d2.dat}
   node [pos=1,pin=0:Special.] {}
   ;
\end{loglogaxis}
\end{tikzpicture}
\end{document}

Comments

Adding comments is currently not enabled.

There are currently 0 comments on this entry.

Features
Tags
Scientific and technical areas

Creative Commons License