Hi all,
I'm getting strange errors trying to use the bar3d method in mplot3d
(I'm using matplotlib 0.99.0 in Ubuntu 9.10 and Python 2.6).
I'm doing something roughly like the example at
http://matplotlib.sourceforge.net/examples/mplot3d/hist3d_demo.html
I've pasted my sample program below, which has 2 cases: In case 1, you
see just what you would expect: 2 rows of bars with increasing size in
the y direction. if you uncomment case 2 (for different bar heights),
you get the following error:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_gtk.py",
line 352, in expose_event
self._render_figure(self._pixmap, w, h)
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_gtkagg.py",
line 75, in _render_figure
FigureCanvasAgg.draw(self)
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py",
line 314, in draw
self.figure.draw(self.renderer)
File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 46,
in draw_wrapper
draw(artist, renderer, *kl)
File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 774, in draw
for a in self.axes: a.draw(renderer)
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/axes3d.py",
line 135, in draw
for col in self.collections]
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/art3d.py",
line 334, in do_3d_projection
z_segments_2d.sort(reverse=True)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
This error gets thrown any time the 2 bars in the same y position have
exactly the same z value: in the sample program the (0,0) value and
(0,1) value are both 1 but it works for any of the 4 pairs. The error
is particularly confusing. even looking at the source of the sort line
in the backtrace, it's not clear where any arrays are being used as
truth values. (just compared for the sort). This can be worked around
by adding a tiny delta to the z values in one of the rows: it only
errors when the corresponding z values match exactly.
Am I doing something wrong here? or is this some kind of bug in the
drawing code?
thanks,
-Derek
the program:
#!/usr/bin/env python2.6
import matplotlib.pyplot as plot
import mpl_toolkits.mplot3d
import numpy
fig2 = plot.figure()
ax2 = mpl_toolkits.mplot3d.Axes3D(fig2)
xpos = numpy.asarray([0, 1, 2, 4, 0, 1, 2, 4])
ypos = numpy.asarray([0, 0, 0, 0, 1, 1, 1, 1])
zpos = numpy.zeros_like(xpos)
dx = 0.05 * numpy.ones_like(zpos)
dy = numpy.ones_like(zpos)
#case 1
dz = numpy.asarray([1,2,3,4,5,6,7,8])
#case 2
#dz = numpy.asarray([1,2,3,4,1,6,7,8])
ax2.bar3d(ypos, xpos, zpos, dy, dx, dz, color='b')
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_zlabel('Z')
plot.show()