4

I have a plot with y-axis values that are rounded to two decimals by tikz. The change in the values occurs in the 3rd and 4th decimal. Because of the rounding constant values are shown on the y-axis:
enter image description here

The MWE is shown below. I've tried setting the ytick property to include the desired values, but this didn't solve the problem.

\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}

How can I force tikz to display the exact y-axis values as set in the ytick property?

1 Answer 1

5

Using number format/precision you can change the default value of 2. Here's an example of change in precision for the y-axis labels from the default 2 to 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}

enter image description here

1
  • Works great. Thanks for the lightning fast response. Mar 18, 2014 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.