4

Is there an easy way to have different tick length for the X and Y axis? While a lot of the tick formating commands have x and y versions to effect only the corresponding axis, I can't find an axis specific version of major tick length. In particular xaxis tickstyle={major tick length=2pt} yields unknown key /tikz/major ticklength.

So far the only solution I can think of is two scale only axis, one for the X ticks and one for the y ticks, however copying all axis formating (i.e. min/max) up to date between axis is cumbersome. If this is the only option is ther an easy way to inherit all options from another axis?

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[ 
      tick align=outside,
      xtick={1,6},
      xticklabels={a,b},
      ytick={0.5,0.6,0.7,0.8,0.9,1.0},
      major tick length=1ex%,
%      x major tick length=0ex
    ]
        \addplot  plot coordinates {
            (1,0.5)     
            (6,1)
        };
    \end{axis}   
\end{tikzpicture}
\end{document}
3

You could just declare the x ticks to be extra, and then modify the style of these extra ticks.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[ 
      tick align=outside,
      xtick=\empty,
      extra x ticks={1,6},
      extra x tick style={major tick length=2pt,blue},
      ytick={0.5,0.6,0.7,0.8,0.9,1.0},
      major tick length=1ex%,
    ]
        \addplot  plot coordinates {
            (1,0.5)     
            (6,1)
        };
    \end{axis}   
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • 1
    @ted I was also wondering why xtick style={major tick length=2pt} won't work. I guess you'd need to ask this question Christian Feuersänger. And the second part I do not understand: if ytick is the empty list, then there is only one style to modify. But you can always use percusse's nice trick to get the list of "extra" ticks from the data. – user121799 Aug 9 '18 at 18:35
  • 3
    @ted, @marmot: the error message complains about an unknown key /tikz/major tick length, here the /tikz/ is the important hint. Using the full path for the key (xtick style={/pgfplots/major tick length=2pt}) works. – Mike Aug 9 '18 at 22:43
  • 1
    @Mike Thanks! (Still strange that for extra x tick style one doesn't need that...) – user121799 Aug 9 '18 at 22:58
  • 2
    @Mike: Thanks, I guess that would be an answer in its own right. I edited the answer so that your solution gets higher visibility. – ted Aug 10 '18 at 9:27
  • 1
    @Mike since the edit was rejected, care to make your comment in an answer for higher visibility? – ted Aug 10 '18 at 14:18

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.