2

I am currently using pgfplots to plot some data in my latex-file and I would like to add certain labels to important values on my xaxis. However these labels have distinct positions (e.g. 0,83) and are not in any way periodic. All solutions I have found so far concern adding xlabels some frequency, which is not what I want.

Is there any way to do this?

  • 3
    Well, yes, you can specify exactly which x-values to have a tick for, with e.g. xtick={0.8,3,7.12}, or if you want these in addition to the default xticks, use extra x ticks={0.8,3,7.12}. You are talking about ticklabels right? – Torbjørn T. Mar 24 '17 at 18:58
  • Yes, but can I add a label there, not a number? In my very example I have critical values that must be labeled as "crit_value_1" or something like that, so what exactly would the syntax be if for instance i wanted to place the label $V_{mol_{krit}} at the value 0.163 on the axis while also keeping the regular number ticks? Also the problem is, that these extra ticks might overlap with the standard tick, so it would be great to place them below the normal ticks if possible – WodkaRHR Mar 25 '17 at 10:17
  • Oh of course, add extra x tick labels={first label, second label, third label} as well. Will add an example in a bit. – Torbjørn T. Mar 25 '17 at 10:27
1

To add ticks in addition to the default numbered ticks, you can use extra x ticks={<comma separated list of x-values>}, and you can specify custom labels for those extra ticks with extra x tick labels={<comma separated list of labels>}. If the extra ticks are such that they will overlap the default ticks, one possible workaround is to shift the extra ticks down a bit, as in the example below.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
 extra x ticks={-1.2,3.2,4.4},
 extra x tick labels={$C_1$, $C_2$, $C_3$},
 extra x tick style={
    ticklabel style={yshift=-10pt}, % if they crash with the default ticks
}
]

\addplot {rnd};

\end{axis}
\end{tikzpicture}
\end{document}

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.