# Usage of /pgf/number format/cd

I'm trying to fix the amount of digits the colorbar has, because the plot is shrinking in size and I wish to animate this plot, so a fixed height and width is mandatory. I still want LaTeX to do the calculations to maximize the size of the final product, so I still used \textheight and \linewidth (amongst others) for dimensions.

I've used /pgf/number format/cd. in other contexts with the same syntax, but in this case it yields error messages, related to about every single value I didn't set explicitly.

The intended effect is to have a set amount of digits in the colorbar, so that the graph doesn't appear to "move".

(The color bar has some weird term \cdot10^{-2} floating above it. I want to get rid of this and I believe this will make the dimension \linewidth suffice to have a fixed width for the graph at any value for \ik smaller than 240.)

\documentclass{article}

\usepackage{pgfplots}
\usepackage{geometry}
%\usepackage{animate}
%\usetikzlibrary{intersections}

\newcommand{\dfa}{3}
\newcommand{\dfb}{9}
\newcommand{\ik}{240}

\begin{document}

\begin{tikzpicture}[
declare function={gamma(\z)=
2.506628274631*sqrt(1/\z)+0.20888568*(1/\z)^(1.5)+0.00870357*(1/\z)^(2.5)-(174.2106599*(1/\z)^(3.5))/25920-
(715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;},
declare function={beta(\x,\y)=(gamma(\x) * gamma(\y)) / (gamma(\x + \y));},
declare function={threedf(\value)= (x^(x/2)*y^(y/2)*\value^(y/2 -1)*(x + y*\value)^(-.5*x -.5*y))/beta(y/2,x/2);},
]
\begin{axis}[
colormap={mycolormap}{color(0cm)=(white); color(1cm)=(blue!75!red)},
colormap name=mycolormap,
%    width=.99\linewidth-\marginparwidth-2\tabcolsep,
height=.49\textheight,
view={150}{45},
enlargelimits=false,
grid=major,
domain=.5:10.5,
y domain=.5:10.5,
xmin = -.5, xmax = 11.5,
ymin = -.5, ymax = 11.5,
zmin = 0, zmax = 1,
samples=11,
xlabel=$df_1$,
ylabel=$df_2$,
zlabel=$F$,
colorbar,
colorbar style={
at={(1.05,0)},
anchor=south west,
height=0.25*\pgfkeysvalueof{/pgfplots/parent axis height},
%        title={$P(x_1,x_2)$},
every tick label/.append style =
{/pgf/number format/.cd,
precision = 2,
fixed zerofill,
fixed, use comma,
},}
]
\pgfmathsetmacro{\result}{((\ik/53+.6)^2+(ln(\ik/53+.6)^2+1.5))/5};
%\path[name path=line] (axis cs:\dfa,\dfb,0) -- (axis cs:\dfa,\dfb,1);
\addlegendentry {$x = \pgfmathprintnumber[fixed, precision=3]{\result}$};
\end{axis}
\end{tikzpicture}

\end{document}

-

After you've set all your number format styles, you need to reset the key directory to the one you were in when you called /pgf/number format/.cd, in this case that's /tikz/.cd:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{geometry}
%\usepackage{animate}
%\usetikzlibrary{intersections}

\newcommand{\dfa}{3}
\newcommand{\dfb}{9}
\newcommand{\ik}{240}

\begin{document}

\begin{tikzpicture}[
declare function={gamma(\z)=
2.506628274631*sqrt(1/\z)+0.20888568*(1/\z)^(1.5)+0.00870357*(1/\z)^(2.5)-(174.2106599*(1/\z)^(3.5))/25920-
(715.6423511*(1/\z)^(4.5))/1244160)*exp((-ln(1/\z)-1)*\z;},
declare function={beta(\x,\y)=(gamma(\x) * gamma(\y)) / (gamma(\x + \y));},
declare function={threedf(\value)= (x^(x/2)*y^(y/2)*\value^(y/2 -1)*(x + y*\value)^(-.5*x -.5*y))/beta(y/2,x/2);},
]
\begin{axis}[
colormap={mycolormap}{color(0cm)=(white); color(1cm)=(blue!75!red)},
colormap name=mycolormap,
%    width=.99\linewidth-\marginparwidth-2\tabcolsep,
height=.49\textheight,
view={150}{45},
enlargelimits=false,
grid=major,
domain=.5:10.5,
y domain=.5:10.5,
xmin = -.5, xmax = 11.5,
ymin = -.5, ymax = 11.5,
zmin = 0, zmax = 1,
samples=11,
xlabel=$df_1$,
ylabel=$df_2$,
zlabel=$F$,
colorbar,
colorbar style={
at={(1.05,0)},
anchor=south west,
height=0.25*\pgfkeysvalueof{/pgfplots/parent axis height},
%        title={$P(x_1,x_2)$},
every tick label/.append style =
{/pgf/number format/.cd,
precision = 2,
fixed zerofill,
fixed, use comma,
/tikz/.cd
}
}
]
\pgfmathsetmacro{\result}{((\ik/53+.6)^2+(ln(\ik/53+.6)^2+1.5))/5};
%\path[name path=line] (axis cs:\dfa,\dfb,0) -- (axis cs:\dfa,\dfb,1);
\addlegendentry {$x = \pgfmathprintnumber[fixed, precision=3]{\result}$};

Thanks! This got rid of the errors. But it didn't get rid of the \cdot10^{-2} that keeps appearing about the color bar. Any suggestions ? –  1010011010 Jun 6 '14 at 10:37
Add scaled y ticks=false to the colorbar style options (see How do you remove the axis multiplier?) –  Jake Jun 6 '14 at 10:40