我有一个图,其中 y 轴值由 tikz 四舍五入到小数点后两位。值的变化发生在小数点后第三位和第四位。由于舍入常数,y 轴上显示的值:
MWE 如下所示。我尝试设置属性ytick
以包含所需的值,但这并不能解决问题。
\documentclass{book}
\usepackage{amsmath}
\usepackage{tikz} % needed to import .tikz graphics
\usepackage{pgfplots} % needed to import .tikz graphics
\begin{document}
Text and image:
\begin{tikzpicture}
\begin{axis}[%
width=0.8\textwidth,
height=0.3\textheight,
scale only axis,
xmin=4000,
xmax=5000,
xtick={4000, 4200, 4400, 4600, 4800, 5000},
xlabel={iteration},
xmajorgrids,
ymin=0.4615,
ymax=0.4645,
ytick={0.4615, 0.4625, 0.4635, 0.4645},
ylabel={$\text{C}_\text{L}\text{ [-]}$},
ymajorgrids,
axis x line*=bottom,
axis y line*=left
]
\addplot [color=blue,solid,line width=1.5pt,forget plot]
table[row sep=crcr]{
3997 0.463684 \\
};
\end{axis}
\end{tikzpicture}%
\end{document}
我如何强制 tikz 显示ytick
属性中设置的精确 y 轴值?
答案1
使用number format/precision
可以更改 的默认值。以下是将 轴标签的精度从默认值更改为2
的示例:y
2
3
\documentclass{book}
\usepackage{amsmath}
\usepackage{tikz} % needed to import .tikz graphics
\usepackage{pgfplots} % needed to import .tikz graphics
\begin{document}
Text and image:
\begin{tikzpicture}
\begin{axis}[%
width=0.8\textwidth,
height=0.3\textheight,
scale only axis,
xmin=4000,
xmax=5000,
xtick={4000, 4200, 4400, 4600, 4800, 5000},
xlabel={iteration},
xmajorgrids,
ymin=0.4615,
ymax=0.4645,
ytick={0.4615, 0.4625, 0.4635, 0.4645},
ylabel={$\text{C}_\text{L}\text{ [-]}$},
yticklabel style={/pgf/number format/precision=3},
ymajorgrids,
axis x line*=bottom,
axis y line*=left
]
\addplot [color=blue,solid,line width=1.5pt,forget plot]
table[row sep=crcr]{
3997 0.463684 \\
};
\end{axis}
\end{tikzpicture}%
\end{document}