1

I am trying to get the histogram intervals to show up in the graph and for them to line up with the bars but i'm not sure where i am going wrong.

This is my code so far:

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{units}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
x tick label style ={font=\normalsize,text width=1.5cm,anchor=north east,rotate=0,align=center}
]
\draw[gray] (0,2) node {$x_1$} (1,1) node {$x_2$} (2,.5) node {$x_3$} (4,0.7) node {$x_4$};
\pgfplothandlerybarinterval
\pgfplotstreamstart
\pgfplotstreampoint{\pgfpoint{0cm}{2cm}}
\pgfplotstreampoint{\pgfpoint{1cm}{1cm}}
\pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}}
\pgfplotstreampoint{\pgfpoint{4cm}{0.7cm}}
\pgfplotstreamend
\pgfusepath{stroke}
\end{axis}
\end{tikzpicture}


\end{document}

and the current output: i want the actual intervals to show up and be aligned with the bars

1
  • Welcome to tex.se! Have you tried removing anchor=north east for x-tick labels? – AboAmmar May 13 at 21:03
1

I'm a bit confused as to why you're using the more primitive form with \pgfplothandlerybarinterval and so on, instead of e.g.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.17}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  ybar interval,
  ymin=0
]

\addplot +[
  nodes near coords,
  point meta=explicit symbolic
]
table [meta=m] {
x y    m
0 2    $x_1$
1 1    $x_2$
2 0.5  $x_3$
4 0.7  $x_4$
};

\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

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.