9

This might be closed for being too localised, in which case I don't know where to get help from but here goes.

I am drawing a histogram with Tikz (using the ybar interval bar chart) and labelling the bars on the x axis. The problem is that one of the bars is very thin, and as a result the labels merge into one another making them unreadable.

Is there any way to move just one label down so that it sits below the others, preferably with a line above indicating where it should be.

Here is an MWE:

\documentclass[oneside,a4paper]{memoir}
\usepackage{libertine}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{rotating}
\usepackage{pgfplots}

\begin{document}

\begin{sidewaysfigure}
\begin{tikzpicture}
\begin{axis}[ybar interval,
  xticklabels={BT,UO,HH1,AOM,WS,D,GS,TSZ,BGE,GM,CW,TI,AC,EH,NCW},
  ymin=0,
  width=20cm, height=15cm,
  enlargelimits={false}%
  ]
  \addplot coordinates
    {(0,0.001690154) (0.42008,0.001788549) (1.46562,0.001654645)
    (2.32381,0.0008229) (2.66407,0.000605811) (3.07674,0.00032906)
    (3.89726,0.000320221) (4.67797,0) (5.52977,0.000493147)
    (6.11783,0.000287141)
    (6.57057,0.000686841) (6.81808,0.001095676) (7.07363,0.002101944) 
    (7.11169,0.000255776) (7.22898,0.000594904) (7.53155,0)};
    \end{axis}
\end{tikzpicture}
\end{sidewaysfigure}

\end{document}
9

Another option would be to use some pins for the problematic labels (not that I am very happy with the result):

\documentclass[oneside,a4paper]{memoir}
\usepackage{libertine}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{rotating}
\usepackage{pgfplots}

\begin{document}

\begin{sidewaysfigure}

\begin{tikzpicture}[small dot/.style={fill=black,circle,scale=0.25}]
\begin{axis}[ybar interval,
  xticklabels={BT,UO,HH1,AOM,WS,D,GS,TSZ,BGE,GM,CW,TI,,,NCW},
  ymin=0,
  width=20cm, height=15cm,
  clip=false,
  enlargelimits={false}%
  ]
  \addplot coordinates
    {(0,0.001690154) (0.42008,0.001788549) (1.46562,0.001654645)
    (2.32381,0.0008229) (2.66407,0.000605811) (3.07674,0.00032906)
    (3.89726,0.000320221) (4.67797,0) (5.52977,0.000493147)
    (6.11783,0.000287141)
    (6.57057,0.000686841) (6.81808,0.001095676) (7.07363,0.002101944) 
    (7.11169,0.000255776) (7.22898,0.000594904) (7.53155,0)};
    \node[small dot,pin={[pin distance=0.8cm]273:{EH}}] at (axis description cs:0.95,0) {};
    \node[small dot,pin=270:{AC}] at (axis description cs:0.9415,0) {};
    \end{axis}
\end{tikzpicture}

\end{sidewaysfigure}

\end{document}

enter image description here

  • Probably the |- tikz notation could give a better result. – cacamailg May 25 '13 at 21:02
9

A pragmatic (that is to say, not very proper) way to do this is to introduce a blank line in the labels in question, for instance by replacing the AC label with {\\[4pt]AC}. Note you also have to set xticklabel style={align=center} for this to work.

\documentclass[border=5mm]{standalone}
\usepackage{libertine}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[ybar interval,
  xticklabels={BT,UO,HH1,AOM,WS,D,GS,TSZ,BGE,GM,CW,TI,{\\[4pt]AC},EH,{\\[4pt]NCW}},
  xticklabel style={align=center},
  ymin=0,
  width=20cm, height=15cm,
  enlargelimits={false}%
  ]
  \addplot coordinates
    {(0,0.001690154) (0.42008,0.001788549) (1.46562,0.001654645)
    (2.32381,0.0008229) (2.66407,0.000605811) (3.07674,0.00032906)
    (3.89726,0.000320221) (4.67797,0) (5.52977,0.000493147)
    (6.11783,0.000287141)
    (6.57057,0.000686841) (6.81808,0.001095676) (7.07363,0.002101944) 
    (7.11169,0.000255776) (7.22898,0.000594904) (7.53155,0)};
    \end{axis}
\end{tikzpicture}

\end{document}
  • wow, that was quick. I tried something like this with just \\ but didn't realise you needed curly brackets round the label. Thank you. – DavidR May 25 '13 at 20:34

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.