11

I have a plot whose y axis is linear with fixed precision and without scaling.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain=-0.1:0.1,
               yticklabel style={scaled ticks=false,
                                 /pgf/number format/fixed,
                                 /pgf/number format/precision=3}]
    \addplot+ { x^3 };
  \end{axis}
\end{tikzpicture}
\end{document}

f(x) = x^3

The y tick labels are very little expressive because pgf rounded 0.0005 to 0.001 in the middle, producing contradictive labels. I do not really want to increase the precision (space constraints on the page), so apparently the best solution is to remove the middle "(-)0.001" ticks. Is there a pgfplots option to achieve this? One that says "do not place ticks such that the label gets rounded", "minimum difference between labels should be 0.001" or similar.

There are literally 100 similar plots in my document coming from data which is subject to change, so manually specifying the y ticks is not the preferred option.

1
  • I would prefer them not to be scaled, because 100 plots, each with different scaling, would be confusing. But yes, maybe adding some (fixed?) scaling is the best solution if what I want to do isn't possible. Jun 6, 2015 at 15:17

1 Answer 1

10

One possibility is to compare whether the trimmed version is different than the original tick number. But this is quite a general spec so if your other 99 plots have different strange intervals I don't think this would be foolproof

\documentclass{standalone}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain=-0.1:0.1,
               yticklabel style={scaled ticks=false,
                                 /pgf/number format/fixed,
                                 /pgf/number format/precision=3},
  yticklabel={%
    \pgfmathprintnumberto[verbatim,fixed,precision=3]{\tick}\possiblytrimmedtick%
    \pgfmathparse{\possiblytrimmedtick == \tick ? int(1):int(0)}%
    \ifnum\pgfmathresult>0\relax$\tick$\else\fi%
 }
]
    \addplot+ { x^3 };
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    Suppressing the tick itself (not just the label) would be ideal, but apart from that, it works very well for me. EDIT: I think I'll just leave it like this. Jun 6, 2015 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .