# first step display a 3d volume

Hello,
I've developped an application that displays volume by using Axes3d module and plot() method. It runs well.
Volumes are expressed in axes x,y,z that represents respectively the latitude,longitude and altitude.
Taking a simple volume : a parallelepiped is defined by 2 series of points :
A1(x1,y1,z_upper), A2(x2,y2,z_upper), A3(x3,y3,z_upper), A4(x4,y4,z_upper)
A11(x1,y1,z_lower), A12(x2,y2,z_lower), A13(x3,y3,z_lower), A14(x4,y4,z_lower)
My objective is to displays the faces of such volume (6 faces in that case).
I suppose that I should trace my volume face by face and the following source code displays a single surface (a face of my volume):

···

##########################################
import gtk
import numpy as np
from matplotlib.patches import Polygon, PathPatch
import mpl_toolkits.mplot3d.art3d as art3d
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas

class SectorDisplay2__:
def __init__(self):
win = gtk.Window()
win.set_default_size(800,800)
vbox = gtk.VBox()

fig = Figure()
canvas = FigureCanvas(fig) # a gtk.DrawingArea

a = np.array([[0,0],[10,0],[10,10],[0,10]])
p = Polygon(a,fill=True)
art3d.pathpatch_2d_to_3d(p, z=3)

ax.set_xlim3d(0, 20)
ax.set_ylim3d(0, 20)
ax.set_zlim3d(0, 20)

vbox.pack_start(canvas)
win.show_all()

# Run the Gtk mainloop
gtk.main()

if __name__ == '__main__':
SectorDisplay2__()
##########################################

But two problems appears :
- the intruction "art3d.pathpatch_2d_to_3d(p, z=3)" can be called only once ! else message "AttributeError: 'PathPatch3D' object has no attribute '_path2d'" is issued
- the isntruction set_xlim3d(0, 20) has no effect : whatever the values supplied to set_slim3d, the minimum/maximum of axes are defined always by the minimum/maximum of the data to display (coordinates of my points).
Thank you for any suggestion (even to represent such volumes in a different way as I choose)

Hello,

I’ve developped an application that displays volume by using Axes3d module and plot() method. It runs well.

Volumes are expressed in axes x,y,z that represents respectively the latitude,longitude and altitude.

Taking a simple volume : a parallelepiped is defined by 2 series of points :

A1(x1,y1,z_upper), A2(x2,y2,z_upper), A3(x3,y3,z_upper), A4(x4,y4,z_upper)

A11(x1,y1,z_lower), A12(x2,y2,z_lower), A13(x3,y3,z_lower), A14(x4,y4,z_lower)

My objective is to displays the faces of such volume (6 faces in that case).

I suppose that I should trace my volume face by face and the following source code displays a single surface (a face of my volume):

##########################################

import gtk

import numpy as np

from matplotlib.patches import Polygon, PathPatch

import mpl_toolkits.mplot3d.art3d as art3d

from matplotlib.figure import Figure

from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas

class SectorDisplay2__:

``````    def __init__(self):

win = gtk.Window()

win.set_default_size(800,800)

vbox = gtk.VBox()

fig = Figure()

canvas = FigureCanvas(fig)  # a gtk.DrawingArea

a = np.array([[0,0],[10,0],[10,10],[0,10]])

p = Polygon(a,fill=True)

art3d.pathpatch_2d_to_3d(p, z=3)

ax.set_xlim3d(0, 20)

ax.set_ylim3d(0, 20)

ax.set_zlim3d(0, 20)

vbox.pack_start(canvas)

win.show_all()

# Run the Gtk mainloop

gtk.main()
``````

if name == ‘main’:

``````    SectorDisplay2__()
``````

##########################################

But two problems appears :

• the intruction “art3d.pathpatch_2d_to_3d(p, z=3)” can be called only once ! else message “AttributeError: ‘PathPatch3D’ object has no attribute ‘_path2d’” is issued

• the isntruction set_xlim3d(0, 20) has no effect : whatever the values supplied to set_slim3d, the minimum/maximum of axes are defined always by the minimum/maximum of the data to display (coordinates of my points).

There have been many errors that have since been fixed in the upcoming release with respect to mplot3d. Whether your problem is fixed or not would be hard to tell without knowing which version of matplotlib you are using. Furthermore, while the pathpatch_2d_to_3d() functions are technically made public (no leading underscore), it really is not intended to be the primary method of creating 3D polygons. Why not just simply use the Poly3DCollection object to create a collection of one polygons? (Yes, I know there is no Polygon3D class… I hope to have this all resolved in the future).

The limit setting should definitely be fixed in the upcoming release, but it should be working in v1.0.1 as well.

Thank you for any suggestion (even to represent such volumes in a different way as I choose)

All that aside, what you are describing is the display of physical 3D objects in an interactive manner. I will tell you right now that you will not be happy with the results. Because matplotlib is inherently a 2D rendering system, the mplot3d module is a bit of a hack to get 3D displays to work. All data used to make the figures are projected from 3D to 2.1D. The “.1” is a z-sort layering value that represents an entire 3d object. Because there is only a single, scalar value to represent the location of the object in depth, matplotlib will not always render the image correctly. This is the layering artifact I spoke of in an earlier email. Imagine 3 square polygons that meet at a corner. At certain orientations, one of those polygons could be drawn as if it was behind the other two polygons, creating an Escher-like effect.

While myself and others are doing work to eliminate this limitation of mplot3d to make matplotlib a one-stop-shop for scientific plotting, I would recommend other python tools such as MayaVi and Chaco:

http://code.enthought.com/projects/mayavi/

http://code.enthought.com/projects/chaco/

I am not personally familiar with these tool, but they are all part of the same SciPy community that we are in. I have also heard good things about Blender, but that is more geared for movie-making.

I hope this helps to save a lot of future aggravation, and I do hope that you continue to use matplotlib for 2d plotting!

Cheers!
Ben Root

···

On Fri, Aug 12, 2011 at 12:21 PM, WALTER Alain <alain.walter@…3719…> wrote: