1

I have a little question regarding the decimal precision of certain single ticks in a plot generated by tikzpicture. Minimal example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=0,xmax=1,
        xtick={0, 0.196,0.514,1},
        ymin=350,ymax=510,
        ytick={350,390,430,470,510},
        xlabel={$\tilde{L}$},
        ylabel= {$T$},
        minor tick num=1,
        ]
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

How can I have the ticks on the x-axis appear with the exact decimal precision I specified in the code (0, 0.196, 0.514, 1)? I know how to set the precision for the entire x-axis, but haven't found out how to do it for single ticks.

Thank you :)

Schiweg
  • 13

1 Answers1

3

The xtick are stored in the \tick macro and typeset with the default xticklabel={\axisdefaultticklabel} with \def\axisdefaultticklabel{$\pgfmathprintnumber{\tick}$}

\pgfmathprintnumber{⟨x⟩} use \pgfmathfloatparsenumber and can be configured to show the number is several different ways, but it can not know how you wrote the number.

To get the desired result, you can give the labels manually like this:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=1,
xtick={0,0.196,0.514,1},
ymin=350, ymax=510,
ytick={350,390,430,470,510},
xlabel={$\tilde{L}$},
ylabel={$T$},
minor tick num=1,
xticklabels={0,0.196,0.514,1},
]
\end{axis}
\end{tikzpicture}
\end{document}

Empty graph with exact x ticks

Edit: I am somewhat wrong - you can also just increase the precision and use no zerofill like this:

x tick label style={/pgf/number format/precision=10},

to get the same result.

  • thank you very much! sometimes the obvious is right in front of your eyes but you don't see it :D – Schiweg Sep 14 '22 at 09:09