3

Hi I am using a mixed notation labelling system (scientific+non-scientific). Due to this the exponent of the scientific notation is causing certain labels to be misaligned. Here is the MWE

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{tikz}
\pgfplotsset{compat=1.9, every tick label/.append style={font=\normalsize}}    

\begin{filecontents}{data.dat}
Keff    PCCR
48.49  1000 
38.52  300  
25     100
19     50
7.4    10
0.844  2
\end{filecontents}

\begin{document}

\pgfplotstableread{data.dat}{\2}

\begin{tikzpicture}
\begin{axis}[
title={Some title},
enlarge x limits=-1,
symbolic x coords={1000,300,100,50,10,2},
xlabel={X-axis},
xtick={1000,300,100,50,10,2},
xticklabels={$\mathrm{1\times10^3}$,$\mathrm{3\times10^2}$,$100$,$50$,$10$,$2$},
scaled ticks=true,
ymin=0.5, ymax=50,
ylabel={Y-axis},
]
\addplot  table [x={PCCR}, y={Keff}] {\2};
\end{axis}
\end{tikzpicture}%
\end{document}
  • Add xticklabel style={text height=2ex}, to the axis options, which will align the labels on their baseline. – Ross Aug 16 '17 at 4:23
5

There is the option typeset ticklabels with strut to align the ticklabels. Just add it to the axis environment options.

% used PGFPlots v1.15
\begin{filecontents}{data.dat}
Keff    PCCR
48.49  1000
38.52  300
25     100
19     50
7.4    10
0.844  2
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
    \pgfplotstableread{data.dat}{\2}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        title={Some title},
        ymin=0.5,
        ymax=50,
        ylabel={Y-axis},
        xlabel={X-axis},
        symbolic x coords={1000,300,100,50,10,2},
        xtick=data,
        xticklabels={
            $1 \times 10^3$,
            $3 \times 10^2$,
            $100$,
            $50$,
            $10$,
            $2$%
        },
        typeset ticklabels with strut,  % <-- added
        enlarge x limits=false,         % <-- (renamed to `false' from `1')
    ]
        \addplot table [x={PCCR}, y={Keff}] {\2};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

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.