Problem viewing mplot3d figure

Hello all.

I'm attempting to use bar3d to plot a packing solution but from some
viewpoints the perspective is wrong (boxes seem overlapped), and with a
large number of boxes the plot is always incoherent.

(I'm using matplotlib 1.0.0 on fedora 14)

Does anyone know how to fix this?

Cheers,
Miguel

Example code:

···

-----------------------------------------------------------------------

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# setup figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim3d(0, 10)
ax.set_ylim3d(0, 10)
ax.set_zlim3d(0, 10)

# boxes
x = [0,2,0,2,0]
y = [0,0,2,2,0]
z = [0,0,0,0,2]
dx = [2,2,2,2,3]
dy = [2,2,2,2,3]
dz = [2,2,2,2,3]
colors = ['b','b','b','b','g']

# draw
ax.bar3d(x, y, z, dx, dy, dz, color=colors, alpha=1.0)

# perspective
ax.view_init(azim=48.0, elev=20.0) # problem
#ax.view_init(azim=48.0, elev=45.0) # no problem

# show
plt.show()

Miguel,

This is a known issue with mplot3d. The issue is that the polygons are essentially abstracted 2-D objects that are using the same backend architecture as the core 2-D plotting software. I think your example script is probably the best example of the problem that I have seen and does a very good job of illustrating the problem.

The crux of the problem is that each polygon is assigned a z-order for layering, and this z-order is determined by (i think) the center-of-mass location of the polygon and how it relates the location of the centers of mass of the other objects. In most graphing situations, this is a good enough hack, but there are too many use-cases where it falls apart.

Because we are limited to a single z-order value for each object, and compositing is done through a 2-D rendering engine, this problem will likely not get solved any time soon, unfortunately. The fix would probably require a complete rewrite of the mpl drawing engine or maybe the utilization of OpenGL?

Sorry I can’t be more helpful in fixing your problem, it has been a aggravating issue for me as well. Thank you for your excellent example script.

Ben Root

···

On Mon, Nov 22, 2010 at 11:44 AM, Miguel Costa <migueldiascosta@…287…> wrote:

Hello all.

I’m attempting to use bar3d to plot a packing solution but from some

viewpoints the perspective is wrong (boxes seem overlapped), and with a

large number of boxes the plot is always incoherent.

(I’m using matplotlib 1.0.0 on fedora 14)

Does anyone know how to fix this?

Cheers,

Miguel

Thank you for your quick (and kind) reply.

I understand that matplotlib is originally 2d - I was hoping, with this new 3d toolkit, to ditch mayavi and use matplotlib for everything :), but that’s ok.

Thanks again,

Miguel

···

On Mon, Nov 22, 2010 at 5:56 PM, Benjamin Root <ben.root@…1304…> wrote:

Miguel,

This is a known issue with mplot3d. The issue is that the polygons are essentially abstracted 2-D objects that are using the same backend architecture as the core 2-D plotting software. I think your example script is probably the best example of the problem that I have seen and does a very good job of illustrating the problem.

The crux of the problem is that each polygon is assigned a z-order for layering, and this z-order is determined by (i think) the center-of-mass location of the polygon and how it relates the location of the centers of mass of the other objects. In most graphing situations, this is a good enough hack, but there are too many use-cases where it falls apart.

Because we are limited to a single z-order value for each object, and compositing is done through a 2-D rendering engine, this problem will likely not get solved any time soon, unfortunately. The fix would probably require a complete rewrite of the mpl drawing engine or maybe the utilization of OpenGL?

Sorry I can’t be more helpful in fixing your problem, it has been a aggravating issue for me as well. Thank you for your excellent example script.

Ben Root