12

simple question (I hope)

Using pgfplots 1.5.1, miktex 2.9 on Windows 7 32 bits. I'd like to hide the tick marks at the right and top side of the plot, but without losing the lines (e.g. keep the plot axis style as box but only keep tick marks in the left y axis and bottom x axis, keeping the lines in the upper x axis (without tick marks nor labels) and right y axis (without tick marks nor labels)

If i use ytick=\empty it removes all of the labels and ticks, but I don't want that, I just want the extra y and x ticks removed.

So far I've tried:

every extra y tick = \empty,
every extra y tick/.style={\empty},
extra y ticks={},
extra ytick =\empty, 
hide extra y ticks,
extra y tick style={tickwidth=0cm,major tick length=0cm},

But no luck,

Any help is much appreciated.

Best regards,

(edit: Forgot to add I'm using Latex->PDF profile)

1 Answer 1

17

The position of the tick marks is set using the key tick pos=<left|right|both> for the x and y axis simultaneously, and xtick pos and ytick pos to set the tick marks separately. In your case, you want to set ytick pos=left.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ytick pos=left]
\addplot {rnd};
\end{axis}
\end{tikzpicture}
\end{document}

The extra y tick options refer to something different: You can manually add additional tick positions, "extra ticks", to highlight certain positions. You specify where to add new tick positions using extra y ticks={<list>}, and set the styles for these extra ticks using extra y tick style=<options>. Here's an example, highlighting the y position 0.5, which ordinarily doesn't get a tick mark:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ytick pos=left,
    extra y ticks={0.5},
    extra y tick style={red, yticklabel pos=right,ytick pos=right}]
\addplot {rnd};
\end{axis}
\end{tikzpicture}
\end{document}
4
  • Brilliant as always Jake, thank you very much.
    – Jose R
    Feb 5, 2012 at 2:57
  • 1
    As an addition, now that Jake has pointed the answer, looking it up in the manual shows that this is on section 4.14.2 Tick Alignment: Positions and Shifts, first paragraph.
    – Jose R
    Feb 5, 2012 at 6:27
  • @JoseR Thanks for the reference to the manual. But for questions that someone has already asked, this site is so much faster ... Jun 5, 2013 at 19:18
  • @Jake If you have a ylabel set, and the extra y ticks are wide, then the ylabel gets offset to the left—presumably because the calculations are taking into account the width of the labels as if they were on the left. Do you know how to fix this?
    – wchargin
    Nov 1, 2014 at 2:46

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.