# Customize y axis in Tikz graph

I would like to customize the y-axis in the graph below such that the numbers 1 and 2 in this axis are not superposed. Your input is very appreciated.

Here is the actual code:

\documentclass[english, 12pt]{article}
\usepackage{tikz}
\usepackage[absolute,overlay]{textpos}

\usepackage{forest}

\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}

\usetikzlibrary{decorations.pathreplacing,arrows.meta,calligraphy}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
%title={},
xlabel={Size of the supermajority ($\alpha$)},
ylabel={Maximum number of equilibria {\large \textbf{$N^{*}$}}},
xmin=0.5, xmax=1,
ymin=1, ymax=100,
xtick={0.5, .6,.7, .8, .9, 1},
ytick={1, 2, 10, 22, 34, 42, 52, 62, 82, 100, 110},
legend pos=outer north east,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
]
color=blue,
mark=*,
]
coordinates {
(.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
};
color=red,
mark=*,
]
coordinates {
(.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

• Please have a look at marked as a code sample Jul 17 '17 at 20:45
• This is not an issue of Tikz or LaTeX. You have logaritmic axes and numbers 1 and 2 overlap. Simply, remove 1 from the ytick list. Jul 18 '17 at 13:16
• I think you should clarify your question. Maybe update it with smtg like: How to adjust overlapping ticks? It is confusing. Jul 18 '17 at 13:26

You can nudge "1" down by 4pt using yticklabel style={yshift={(\ticknum == 0 ? "-4pt" : 0)}} and "2" up by 3pt using yticklabel style={yshift={(\ticknum == 1 ? "3pt" : 0)}}.

What the first key is saying is:

1. yticklabel style = ... Set the yticklabel style for the values given in ytick={...}
2. yshift= ... Move the yticklabel vertically
3. \ticknum == 0 ? ... Test if this is the first ticknum (Note that tiknum starts at 0)
4. "-4pt" ... If this is the first tick, apply a vertical shift downwards of 4pt
5. : 0 ... Otherwise do nothing

I also added enlarge y limits=true to add some space between "1" and the x-axis.

This is the result:

This is the MWE:

\documentclass[english, 12pt]{article}
\usepackage{tikz}
\usepackage[absolute,overlay]{textpos}
\usepackage{forest}
\usepackage{textcomp}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9} % Compatability could be set to 1.15 or newest

\usetikzlibrary{decorations.pathreplacing,arrows.meta,calligraphy}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
%title={},
xlabel={Size of the supermajority ($\alpha$)},
ylabel={Maximum number of equilibria {\large \textbf{$N^{*}$}}},
xmin=0.5, xmax=1,
ymin=1, ymax=100,
enlarge y limits=true,
xtick={0.5, .6,.7, .8, .9, 1},
ytick={1, 2, 10, 22, 34, 42, 52, 62, 82, 100, 110},
yticklabel style={yshift={(\ticknum == 0 ? "-4pt" : 0)}},
yticklabel style={yshift={(\ticknum == 1 ? "3pt" : 0)}},
legend pos=outer north east,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
]
color=blue,
mark=*,
]
coordinates {
(.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
};
color=red,
mark=*,
]
coordinates {
(.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

• @JBT You are welcome. Glad it was useful.
– Ross
Jul 18 '17 at 16:30

You could try, for example

yticklabels={,,10,22,34,42,52,62,82,100,110},


as demonstrated in the following:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
%title={},
xlabel={Size of the supermajority ($\alpha$)},
ylabel={Maximum number of equilibria {\large \textbf{$N^{*}$}}},
xmin=0.5, xmax=1,
ymin=1, ymax=100,
xtick={0.5, .6,.7, .8, .9, 1},
ytick={1, 2, 10, 22, 34, 42, 52, 62, 82, 100, 110},
yticklabels={,,10,22,34,42,52,62,82,100,110},
legend pos=outer north east,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
]
color=blue,
mark=*,
]
coordinates {
(.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
};
color=red,
mark=*,
]
coordinates {
(.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
};

This is not an issue of Tikz. Simply remove 1 from the ytick list.