4

I have a graph in 3D space and I'd like to add a histogram along the vertical axis. The bars are supposed to be spaced equally along the vertical axis. I am, however, unable to get the positions of the bars correctly. Here is a MWE of what I have tried so far.

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  view={35}{15},
  height=3in, width=3in,
  xmin=0, xmax=1,
  ymin=0, ymax=1,
  zmin=0, zmax=1,
  3d box=complete,
  xlabel=$x$, ylabel=$y$, zlabel=$z$]
\addplot3 [xbar,bar width=2pt] coordinates{
(0.51,0,0.00) (1.00,0,0.05) (0.82,0,0.10) (0.45,0,0.15) (0.20,0,0.20) (0.30,0,0.25) (0.04,0,0.30) (0.06,0,0.35) (0.19,0,0.40) (0.17,0,0.45) (0.12,0,0.50) (0.09,0,0.55) (0.13,0,0.60) (0.30,0,0.65) (0.11,0,0.70) (0.28,0,0.75) (0.06,0,0.80) (0.21,0,0.85) (0.46,0,0.90) (0.24,0,0.95) (0.01,0,1.00)
};
\end{axis}
\end{tikzpicture}

\end{document}

My understanding is that the last element of each coordinate point should determine the position of the bar along the Z-axis, while the first element specifies the height. I meant to have the bars equally spaced, though, as seen from the below picture, the output is not produced as such.

enter image description here

Also, my second question is that how I can get the bars rotated around the Z-axis such that they lie flatly on the Y-Z plane rather than hanging up in the space like in the picture above.

2
  • 1
    You need to add a slant to those lines, something like yslant=0.4 seems to produce ok results. Also How to compute xslant and yslant may help. May 9, 2014 at 19:22
  • Thanks, @PeterGrill. Sounds like yslant does the rotation trick! I am still wondering why the bar positions are messed up.
    – Ali
    May 9, 2014 at 19:31

1 Answer 1

2

Quoting from the pgfplots manual:

4.6.11 About 3D Const Plots and 3D Bar Plots

There are currently no equivalents of const plot and its variants or the bar plot types like ybar for three dimensional axes, sorry.

Your request is actually a feature request. I will write it to the todo list of pgfplots.

2

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.