/pgf/number format/cd 的用法

/pgf/number format/cd 的用法

我正在尝试修复颜色条的数字数量,因为绘图的尺寸正在缩小,并且我希望为该绘图添加动画效果,因此必须使用固定的高度和宽度。我仍然希望 LaTeX 进行计算以最大化最终产品的尺寸,因此我仍然使用\textheight\linewidth(以及其他)作为尺寸。

我在其他上下文中使用过/pgf/number format/cd.相同的语法,但在这种情况下,它会产生错误消息,与我没有明确设置的每个值有关。

预期效果是在颜色条中设置一定数量的数字,以便图形看起来不会“移动”。

http://i.imgur.com/SnxptGO.png?1

(颜色条\cdot10^{-2}上方漂浮着一些奇怪的术语。我想摆脱它,我相信这将使尺寸\linewidth足以使图形具有\ik小于 240 的任何值的固定宽度。)

\documentclass{article}

\usepackage{pgfplots}
\usepackage{geometry}
\pgfplotsset{compat=newest}
%\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);
\addplot3 [surf] {threedf(\result)};
\addlegendentry {$x = \pgfmathprintnumber[fixed, precision=3]{\result}$};
\end{axis}
\end{tikzpicture}


\end{document}

答案1

设置完所有number format样式后,您需要将密钥目录重置为您调用时所在的目录/pgf/number format/.cd,在本例中为/tikz/.cd

\documentclass{article}

\usepackage{pgfplots}
\usepackage{geometry}
\pgfplotsset{compat=newest}
%\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);
\addplot3 [surf] {threedf(\result)};
\addlegendentry {$x = \pgfmathprintnumber[fixed, precision=3]{\result}$};
\end{axis}
\end{tikzpicture}


\end{document}

相关内容