So I am attempting to create some simple sudo random data and plot the results with a trend line. Best fit linear approximation. I am trying to create something that looks like the graph below
Here is what I have so far
Problems
- I do not not know I can use
axis y discontinuity=parallelin both directions to obtain the blue discontinuties. - My randomization of variables and plotting feels very convoluted
Short explanation
I got the following function
f(\T) = 1.08 * 10^10 * exp(-12667/\T)
From which I am trying to create some fictional experimental data that fits this equation (Arrhenius equation). Then I am trying to plot the data in a log plot with a linear regression. I do this as follows
\pgfmathsetmacro{\arrenhiusOneX}{int(2*random(300,305))}
\pgfkeys{/pgf/fpu}
\pgfmathparse{f(\arrenhiusOneX)+2*rand}
\edef\arrenhiusOneY{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusOneX)}
\edef\arrenhiusOneYi{\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
I manually add some noise on purpose. Because the values are too big, I have to use the fpu library. Then I put these points into a table
\pgfplotstableread{
X Y
{\arrenhiusZeroXi} {\arrenhiusZeroYi}
.
.
.
}\datatable
From which I can create the linear fit line with.
\addplot [thick, red] table[
y={create col/linear regression={y=Y}}
] % compute a linear regression from the input table
{\datatable};
However, as mentioned previously this feels convoluted.
Code
\documentclass[margin=5mm]{standalone}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{
compat=1.16,
% declare your function here ...
/pgf/declare function={
f(\T) = 1.08 * 10^10 * exp(-12667/\T);
},
}
\pgfmathsetmacro{\arrenhiusZeroX}{592}
\pgfmathsetmacro{\arrenhiusOneX}{int(2*random(300,305))}
\pgfmathsetmacro{\arrenhiusTwoX}{int(2*random(310,315))}
\pgfmathsetmacro{\arrenhiusThreeX}{int(2*random(325,327))}
\pgfmathsetmacro{\arrenhiusFourX}{558}
\pgfmathsetmacro{\arrenhiusZeroXi}{1/\arrenhiusZeroX}
\pgfmathsetmacro{\arrenhiusOneXi}{1/\arrenhiusOneX}
\pgfmathsetmacro{\arrenhiusTwoXi}{1/\arrenhiusTwoX}
\pgfmathsetmacro{\arrenhiusThreeXi}{1/\arrenhiusThreeX}
\pgfmathsetmacro{\arrenhiusFourXi}{1/\arrenhiusFourX}
\pgfkeys{/pgf/fpu}
\pgfmathparse{f(\arrenhiusOneX)+2*rand}
\edef\arrenhiusOneY{\pgfmathresult}
\pgfmathparse{f(\arrenhiusTwoX)+2*rand}
\edef\arrenhiusTwoY{\pgfmathresult}
\pgfmathparse{f(\arrenhiusThreeX)+2*rand}
\edef\arrenhiusThreeY{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusZeroX)}
\edef\arrenhiusZeroYi{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusOneX)}
\edef\arrenhiusOneYi{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusTwoX)}
\edef\arrenhiusTwoYi{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusThreeX)}
\edef\arrenhiusThreeYi{\pgfmathresult}
\pgfmathparse{ln(\arrenhiusFourX)}
\edef\arrenhiusFourYi{\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
\pgfplotstableread{
X Y
{\arrenhiusZeroXi} {\arrenhiusZeroYi}
{\arrenhiusOneXi} {\arrenhiusOneYi}
{\arrenhiusTwoXi} {\arrenhiusTwoYi}
{\arrenhiusThreeXi} {\arrenhiusThreeYi}
{\arrenhiusFourXi} {\arrenhiusFourYi}
}\datatable
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {\ce{2NO2 -> 2NO + O2}},
xlabel={1/T [\si{\per\kelvin}]},
ylabel={ln(k [\SI{e-4}{\cm\cubed\per\mol\per\s}]})],
minor x tick num=4,
title = {\ce{2NO2 -> 2NO + O2}},
xmin=0.0015, xmax=0.0017,
ymin=0,ymax=4.5,
ytick={0,0.5,...,4},
minor grid style={black!25},
major grid style={black},
grid=both,
minor y tick num=4,
ylabel=Error]
\addplot [only marks,
every mark/.append style={solid, fill=black},
mark = square*] table {\datatable};
\addplot [thick, red] table[
y={create col/linear regression={y=Y}}
] % compute a linear regression from the input table
{\datatable};
\end{axis}
\end{tikzpicture}
\end{document}


