我正在尝试修改 TikZ 图片中的轮廓标签样式。我希望标签值为 0.0 格式,而不是整数。以下代码生成一个图片,其中标签显示为没有小数点的整数。
\documentclass[crop=true, border=0mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top,
title = {$\omega_\phi\left(x, \sigma\right) = \frac{\Gamma}{\pi{R_c}^2}\exp\left[-\frac{\left(x-x_0\right)^2+\left(\sigma-R_0\right)^2}{{R_c}^2}\right]$},
xmin=2, xmax=3,
ymin=2, ymax=3,
view={0}{90},
xlabel = {$x$},
ylabel = {$\sigma$},
]
\addplot3[
contour gnuplot = {contour label style={nodes={text=black}}},
samples=10,
contour/draw color={black},
]
{1/3.1415927/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
\end{axis}
\end{tikzpicture}
\end{document}
下图是上述代码的2000个样本的结果。
如何使用以下代码调整标签值格式?由于某些原因,LaTeX 会抱怨未知键。
contour label style={
/pgf/number format/fixed,
/pgf/number format/precision=1,
}
答案1
代码
\documentclass[crop=true, border=0mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top,
title = {$\omega_\phi\left(x, \sigma\right) = \frac{\Gamma}{\pi{R_c}^2}\exp\left[-\frac{\left(x-x_0\right)^2+\left(\sigma-R_0\right)^2}{{R_c}^2}\right]$},
xmin=2, xmax=3,
ymin=2, ymax=3,
view={0}{90},
xlabel = {$x$},
ylabel = {$\sigma$},
]
\addplot3[
contour gnuplot={
contour label style={
nodes={text=black},
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1,
}
},
samples=50,
contour/draw color={black},
]
{1/3.1415927/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
\end{axis}
\end{tikzpicture}
\end{document}