8

I have been trying to find how to place the y ticks Normal and Special inside the bars rather than to the left of the bars.

Below is the code of the most recent attempt:

\begin{tikzpicture}
 \begin{axis}[
  %axis lines={left, },% xtick=\empty
  %axis lines={left, right},
  %legend style={draw=none},
  %
  %/pgfplots/axis y line*=box|left|middle|center|right|none 219
  %giving up on removing top and right lines%%%
  compat=newest,
  title=Gears Rxf,
  xbar, xmin=0,
  bar width= 1.0cm,
  width=12cm, height=5cm, enlarge y limits=0.5,
  xlabel={Points},
  %==========
  y=2.5cm,
  symbolic y coords={Special,Normal},
  ytick={Debugging, Normal}, 
  y tick label style={rotate=0,anchor=east},
  %yticklabel style={inner ysep=0pt, anchor=south east},
  nodes near coords, nodes near coords align={horizontal},
 ]
 \addplot[color=gray,fill] coordinates {(2.31,Normal)};
 \addplot[color=black,fill] coordinates {(2.58,Special)};
 \end{axis}
\end{tikzpicture}

Actual Actual Graph Gears Rx


Desired Desired Graph Gears Rx

9

Add axis on top to avoid bars overprinting labels.

Then we want

y tick label style={anchor=west,color=white,xshift=\pgfkeysvalueof{/pgfplots/major tick length}},

to:

  • anchor at the west of the label,
  • colored white so the text shows over black, and
  • shifted one tick width to the right, since presumably you did not want to change the position of the tick marks themselves.

We also need bar shift=0pt to center the labels vertically in the bars.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[
  %axis lines={left, },% xtick=\empty
  %axis lines={left, right},
  %legend style={draw=none},
  %
  %/pgfplots/axis y line*=box|left|middle|center|right|none 219
  %giving up on removing top and right lines%%%
  compat=newest,
  axis on top,
  title=Gears Rxf,
  xbar, xmin=0,
  bar width= 1.0cm,
  width=12cm, height=5cm, enlarge y limits=0.5,
  xlabel={Points},
  %==========
  y=2.5cm,
  symbolic y coords={Special,Normal},
  ytick={Special, Normal}, 
  y tick label style={anchor=west,color=white,xshift= \pgfkeysvalueof{/pgfplots/major tick length}},
  bar shift=0pt,
  %yticklabel style={inner ysep=0pt, anchor=south east},
  nodes near coords, nodes near coords align={horizontal},
 ]
 \addplot[color=gray,fill] coordinates {(2.31,Normal)};
 \addplot[color=black,fill] coordinates {(2.58,Special)};
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
1

Add bar shift=0pt into addplot parameter:

\documentclass{standalone}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[
  %axis lines={left, },% xtick=\empty
  %axis lines={left, right},
  %legend style={draw=none},
  %
  %/pgfplots/axis y line*=box|left|middle|center|right|none 219
  %giving up on removing top and right lines%%%
  compat=newest,
  title=Gears Rxf,
  xbar, xmin=0,
  bar width= 1.0cm,
  width=12cm, height=5cm, enlarge y limits=0.5,
  xlabel={Points},
  %==========
  y=2.5cm,
  symbolic y coords={Special,Normal},
  ytick={Special, Normal}, 
  y tick label style={rotate=45,anchor=east},
  %yticklabel style={inner ysep=0pt, anchor=south east},
  nodes near coords, nodes near coords align={horizontal},
 ]
 \addplot[bar shift=0pt,color=gray,fill] coordinates {(2.31,Normal)};
 \addplot[bar shift=0pt,color=black,fill] coordinates {(2.58,Special)};
 \end{axis}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • 1
    The labels are still to the left of the bars, not inside them. – Paul Gessler Jan 7 '15 at 13:37
  • @ferahfeza Thanks for your answer but as Paul Gessler wrote The labels are still to the left of the bars, not inside them. I edited the question adding an image of the desired graph – user454322 Jan 7 '15 at 13:49

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.