I’m having trouble getting pgfplots to typeset very small numbers, e.g. 6.82e-08
. I don’t know if the problem lies in it being a very small number, or if it’s because of the interaction with reading variable data generated from gnuplot.
The example below will generate two plots. The first is generated from “external” data, and has gnuplot generate the exponential regression. It saves the fitted variables in a file that pgfplots should read and pretty-print in the plot legend. It works as intended for variables b
and c
but not for a
.
At first I thought it was related to the number not being rendered in scientific notation, but forcing it through \pgfmathprintnumber[sci]
still outputs wrongly, which leads me to believe the problem lies with the gnuplot interaction.
I want the first graph to have the same legend as the second, but still have it be generated as I’m using this in a macro for different sets of data. What should I do?
Minimal example:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents}{data.csv}
x, y
2, 0.000058
3, 0.001888
4, 0.058763
5, 1.78986
\end{filecontents}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot [raw gnuplot, smooth] gnuplot {
f(x)=(a)*(b^(c*x));
a=6.8e-8;
b=2.7;
c=3.4;
fit f(x) 'data.csv' using 1:2 via a,b,c;
plot f(x);
set print "data.csv.dat";
print a,b,c;
};
\addlegendentry{
\pgfplotstableread{data.csv.dat}\parameters
\pgfplotstablegetelem{0}{0}\of\parameters \pgfmathsetmacro{\paramA}{\pgfplotsretval}
\pgfplotstablegetelem{0}{1}\of\parameters \pgfmathsetmacro{\paramB}{\pgfplotsretval}
\pgfplotstablegetelem{0}{2}\of\parameters \pgfmathsetmacro{\paramC}{\pgfplotsretval}
$y=\pgfmathprintnumber[sci]{\paramA} \cdot \pgfmathprintnumber{\paramB}^{\pgfmathprintnumber{\paramC} \cdot x}$
}
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot [raw gnuplot, smooth] gnuplot {
plot (6.82564001285694e-08)*(2.71554805209898^(3.41986746643527*x));
};
\addlegendentry{
$y=\pgfmathprintnumber{6.82564002501364e-08} \cdot \pgfmathprintnumber{2.71554805209898}^{\pgfmathprintnumber{3.41986746643527} \cdot x}$
}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Result:
data.csv.dat.
6.82564001285694e-08 2.71565816582345 3.41972869952421
erroneous plot:
desired plot:
pgfplotstable
, the precision is limited to10^{-6}
– user31729 Mar 21 '15 at 14:26