2

Is it possible to shift a single x tick label to the right?

I created a boxplot and set the x ticks at the important positions (lower whisker, median aso.) Due to the fact that some points lie close together, some of the corresponding x tick labels coincide.

Now I want to move the overlapping x tick label to the right, so that all labels are legible. (I know that rotating the labels by 45° would be a possible solution, but I prefer horizontal labels.)

Here is a small example:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}                              
\usepackage[T1]{fontenc}  
\usepackage{tikz,pgf}
\usepackage{pgfplots}
\usepackage{float}                                                  

\usepgfplotslibrary{dateplot, statistics, groupplots}

\pgfplotsset{
compat=newest,
every axis/.append style={
    tick label style={font=\tiny},
    title style={font=\tiny}}}

\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
    y tick label style={%
            /pgf/number format/set thousands separator={\,},%
            /pgf/number format/use comma%
            },
    x tick label style={%
            /pgf/number format/set thousands separator={\,},%
            /pgf/number format/use comma,%
            align=center%
            },
    /pgfplots/xtick pos=left,
    /pgfplots/ytick pos=left,
    /pgfplots/xtick align=center,
    /pgfplots/ytick align=center,
    ytick=\empty,
    ymin=0.5,
    ymax=1.5,
    width=9cm,
    y=1.5cm,
    xtick={2,4.5,5,7.5,9},
    xticklabels={00:10:00,00:20:00,00:30:00,01:00:00,01:20:00},
    ]
\addplot[
    boxplot prepared={
    median=5,
    upper quartile=7.5,
    lower quartile=4.5,
    upper whisker=9,
    lower whisker=2,
    box extend=0.5,  
    whisker extend=0.25,
    every median/.style={black, thick}
    },
    ] coordinates {};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

3
  • A tricky solution like replace "00:30:00" by "{\hspace{1cm} 00:30:00}" is not valid? Nov 7, 2016 at 19:19
  • 2
    Hi, welcome. This question is similar, perhaps you can adapt the solution to your case: tex.stackexchange.com/questions/239935/… Nov 7, 2016 at 19:37
  • 3
    I'm voting to close this question as off-topic because it was solved in the comments. Nov 10, 2016 at 21:41

0

Browse other questions tagged .