4

enter image description hereI 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,
    ]
    \addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
        (.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
    };
    \addlegendentry{Maximum number of equilibria}
    \addplot[
    color=red,
    mark=*,
    ]
    coordinates {
        (.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
    };
    \addlegendentry{minimum number of equilibria}
    \end{axis}
    \end{tikzpicture}
        \end{figure}
\end{document}
3
  • 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.
    – berkus
    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.
    – berkus
    Jul 18 '17 at 13:26
1

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: enter image description here

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,
    ]
    \addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
        (.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
    };
    \addlegendentry{Maximum number of equilibria}
    \addplot[
    color=red,
    mark=*,
    ]
    coordinates {
        (.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
    };
    \addlegendentry{minimum number of equilibria}
    \end{axis}
    \end{tikzpicture}
        \end{figure}
\end{document}
1
  • @JBT You are welcome. Glad it was useful.
    – Ross
    Jul 18 '17 at 16:30
2

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,
    ]
    \addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
        (.5,2)(.6,22)(0.67,34)(0.7,42)(0.75,52)(.8,62)(0.9,82)(1,100)
    };
    \addlegendentry{Maximum number of equilibria}
    \addplot[
    color=red,
    mark=*,
    ]
    coordinates {
        (.5,1)(.6,1)(0.67,1)(0.7,1)(0.75,1)(.8,1)(0.9,1)(1,1)
    };
    \addlegendentry{minimum number of equilibria}
    \end{axis}
    \end{tikzpicture}
\end{document}
2
  • @JBT could you update your question with a screenshot of what you have, and what you would like to receive. At the moment, it seems that I've misunderstood
    – cmhughes
    Jul 17 '17 at 20:56
  • @JBT Hi there, I'm not entirely sure why you seem to have proposed an edit to cmhughes's answer, with your explanation of what you would like as the edit reason. You should instead edit your original question (which you can do for yourself) to include the screenshot and the things that you would like help with so as to make the question clearer for everybody.
    – Au101
    Jul 17 '17 at 21:46
0

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

enter image description here

1
  • I want to keep 1.
    – JBT
    Jul 18 '17 at 13:22

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.