2

I would like to know how could I exclude 0 of this axis format

yticklabel style={/pgf/number format/.cd,sci,sci zerofill,precision=1}

In order to avoid this.

enter image description here

the most similar what I've got is using this code (as MWE)

\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[left=2cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}

\usepackage{xcolor}



\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[grid=major, scaled ticks=false,scale=2.2, y post scale=2, yticklabel style={/pgf/number format/.cd, 1000 sep={\;}}]
\addplot+[
        only marks,
        mark=+,
        color=NavyBlue,
        error bars/.cd,
        x dir=both, x explicit,
        y dir=both, y explicit,
        ]
        table[y error=yerror,x error=xerror]
            {NmP3pgf1.dat};
\addplot[
        red,
        domain=-3:1
        ] {-120322.13*x + 53246.18};  
\end{axis}
\end{tikzpicture}
\caption{pgfplots}
\end{figure}
\end{document}

Which produces this

enter image description here

being this NmP3pgf1.dat

x           y                xerror       yerror  label
0.00        52080.65         0.01         648.31   a
-0.80       148381.84        0.01       2618.50   a
-2.80       391752.88        0.01       9554.95   a
3

Essentially Jake's solution is correct as usual but here your numbers are too big for the \ifdim test. Hence a bit more lower level pgf number formatting is needed.

If you just use the following it will perform a test for zero and execute the correct branch of the if.

yticklabel={\pgfkeys{/pgf/fpu}%
    \pgfmathparse{\tick}%
    \pgfmathfloatifflags{\pgfmathresult}{0}{0}{%
        \pgfmathprintnumber[sci,sci zerofill,precision=1]{\tick}%
    }%
    \pgfkeys{/pgf/fpu=false}%
}

enter image description here

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.