
Das folgende MWE zeigt eine Vorlage, die ich an der Universität verwende, um Kalibrierungsdaten und die entsprechende lineare Regression anzuzeigen. Jetzt habe ich gefragt, ob ich einen X-Wert für einen gegebenen Y-Wert berechnen und ihn in einem Diagramm ähnlich dem folgenden Bild anzeigen kann.
Bisher musste ich die Werte per Hand berechnen und in die heißgeliebten pgfplots einspeisen.
Ich hoffe, dass die Frage klar genug ist und dass es eine halbautomatische Lösung gibt.
PS: Ich verwende LuaLaTeX zum Kompilieren. Zur besseren Bedienbarkeit habe ich die von mir verwendete Schriftart auskommentiert.
\documentclass{standalone}
\usepackage{luaotfload}
\usepackage[no-math]{fontspec}
%\defaultfontfeatures{Ligatures=TeX} %,Scale=MatchLowercase} still buggy
%\setmainfont{Linux Biolinum O}
%\setsansfont{Linux Biolinum O}
%\setmonofont{Linux Libertine Mono O}
\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage[autostyle=true]{csquotes}
\usepackage[
tbtags,
sumlimits,
intlimits,
namelimits
]{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amscd}
\setcounter{MaxMatrixCols}{12}
\usepackage[german]{translator}
\usepackage[detect-all=true]{siunitx}
\sisetup{
% strict,
output-decimal-marker={,},
exponent-product=\cdot,
text-micro={\fontfamily{mdbch}\textmu},
math-micro=\muup
}
\DeclareSIUnit\molar{M}
\usepackage[math-style=ISO,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}
\usepackage{lualatex-math}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Kalibration für den Versuch XYZ},
/pgf/number format/use comma,
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
x label style={at={(axis description cs:.5,-.025)},anchor=north},
y label style={at={(axis description cs:.05,.5)},anchor=south},
xlabel=Konzentration~{[}\si{\milli\gram\per\milli\litre}{]},
ylabel=Extinktion,
% xtick={0,60,90,120,150,180},
x tick label style={rotate=90,anchor=east},
legend cell align=left,
legend pos=north west,
]
\addplot[
only marks,
thick,
color=black,
mark=*,
mark options={fill=red},
] table [x=X,y=Y, row sep=\\] {
X Y\\
0 0\\
25 0.17\\
50 0.43\\
75 0.60\\
100 0.79\\
125 1.01\\
};
\addlegendentry{Messpunkte}
\addplot[thick,color=blue] table[row sep=\\,y={create col/linear regression={y=Y}},mark=none] {
X Y\\
0 0\\
25 0.17\\
50 0.43\\
75 0.60\\
100 0.79\\
125 1.01\\
};
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$};
\draw[thick,color=blue] (axis cs:20,-1) -- (axis cs:20,.15609);
\draw[thick,color=blue] (axis cs:-20,.15609) -- (axis cs:20,.155);
\node [coordinate,pin=below right:{\scriptsize\textit{minimal effective concentration}}] at (axis cs:20,.15609) {};
\end{axis}
\end{tikzpicture}
\end{document}
Antwort1
Der einfachste Weg, diese Linien zu zeichnen, besteht darin, alle Werte als Makros zu definieren und den x-Wert mit zu berechnen \pgfmathparse{(\myY-\pgfplotstableregressionb)/\pgfplotstableregressiona}
. Das Ergebnis kann als gespeichert werden \pgfmathsetmacro\myX{\pgfmathresult}
.
% % Y-Value % %
\def\myY{0.155}
% % % % % % % %
\def\xMin{0}
\def\yMin{0}
Für die Schnittpunkte mit der Achse werden die Minima verwendet.
\documentclass{standalone}
\usepackage[german]{translator}
\usepackage[detect-all=true]{siunitx}
\sisetup{
% strict,
output-decimal-marker={,},
exponent-product=\cdot,
text-micro={\fontfamily{mdbch}\textmu},
math-micro=\muup
}
\DeclareSIUnit\molar{M}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
% % Y-Value % %
\def\myY{0.155}
% % % % % % % %
\def\xMin{0}
\def\yMin{0}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Kalibration für den Versuch XYZ},
/pgf/number format/use comma,
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
x label style={at={(axis description cs:.5,-.025)},anchor=north},
y label style={at={(axis description cs:.05,.5)},anchor=south},
xlabel=Konzentration~{[}\si{\milli\gram\per\milli\litre}{]},
ylabel=Extinktion,
% xtick={0,60,90,120,150,180},
xmin=\xMin,
ymin=\yMin,
x tick label style={rotate=90,anchor=east},
legend cell align=left,
legend pos=north west,
]
\addplot[
only marks,
thick,
color=black,
mark=*,
mark options={fill=red},
] table [x=X,y=Y, row sep=\\] {
X Y\\
0 0\\
25 0.17\\
50 0.43\\
75 0.60\\
100 0.79\\
125 1.01\\
};
\addlegendentry{Messpunkte}
\addplot[thick,color=blue] table[row sep=\\,y={create col/linear regression={y=Y}},mark=none] {
X Y\\
0 0\\
25 0.17\\
50 0.43\\
75 0.60\\
100 0.79\\
125 1.01\\
};
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$};
\pgfmathparse{(\myY-\pgfplotstableregressionb)/\pgfplotstableregressiona}
\pgfmathsetmacro\myX{\pgfmathresult}
\draw[thick,color=blue] (axis cs:\myX,\yMin) -- (axis cs:\myX,\myY);
\draw[thick,color=blue] (axis cs:\xMin,\myY) -- (axis cs:\myX,\myY);
\node [coordinate,pin=below right:{\scriptsize\textit{minimal effective concentration}}] at (axis cs:\myX,\myY) {};
\end{axis}
\end{tikzpicture}
\end{document}