Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like a depth buffer in matplotlib?

I'm trying to plot some curves with matplotlib.
But, since these curve overlap with each other from viewport.
So only z-order can not help here.

I wonder if there is a function works like a depth buffer in matplotlib.
I'm plotting something like this.
And the red line should not always on top in 3D space.

like image 223
silvesthu Avatar asked Aug 30 '12 09:08

silvesthu


2 Answers

I think it's difficult to do such things in matplotlib, since it's a 2D plot library with some 3D plot ability. I recommend some real 3D plot library, such as visvis, mayavi, vpython. For example, in visvis, you can create a 3D curve like:

enter image description here

import numpy as np
import visvis as vv
app = vv.use()

f = vv.clf()
a = vv.cla()

angle = np.linspace(0, 6*np.pi, 1000)
x = np.sin(angle)
y = np.cos(angle)
z = angle / 6.0
vv.plot(x, y, z, lw=10)

angle += np.pi*2/3.0
x = np.sin(angle)
y = np.cos(angle)
z = angle / 6.0 - 0.5
vv.plot(x, y, z, lc ="r", lw=10)

app.Run()

mayavi:

enter image description here

import numpy as np
from mayavi import mlab

angle = np.linspace(0, 6*np.pi, 1000)
x = np.sin(angle)
y = np.cos(angle)
z = angle / 6.0

mlab.plot3d(x, y, z, color=(1,0,0), tube_radius=0.1)

angle += np.pi*2/3.0
x = np.sin(angle)
y = np.cos(angle)
z = angle / 6.0 - 0.5
mlab.plot3d(x, y, z, color=(0,0,1), tube_radius=0.1)

mlab.axes()
mlab.show()
like image 61
HYRY Avatar answered Oct 24 '22 03:10

HYRY


You could try to use the fill_between function to color the regions manually perhaps. See the random walkers example:

http://matplotlib.sourceforge.net/users/recipes.html

http://matplotlib.sourceforge.net/users/recipes-6.py

like image 1
reptilicus Avatar answered Oct 24 '22 03:10

reptilicus