python - Matplotlib -- mplot3d: triplot projected on z=0 axis in 3d plot? -



python - Matplotlib -- mplot3d: triplot projected on z=0 axis in 3d plot? -

i'm trying plot function in 2 variables, piecewise defined on set of known triangles, more or less so:

import matplotlib.pyplot plt mpl_toolkits.mplot3d import axes3d import random def f( x, y): if x + y < 1: homecoming 0 else: homecoming 1 x = [0, 1, 1, 0] y = [0, 0, 1, 1] tris = [[0, 1, 3], [1, 2,3]] fig = plt.figure() ax = fig.add_subplot( 121) ax.triplot( x, y, tris) xs = [random.random() _ in range( 100)] ys = [random.random() _ in range( 100)] zs = [f(xs[i], ys[i]) in range( 100)] ax2 = fig.add_subplot( 122, projection='3d') ax2.scatter( xs, ys, zs) plt.show()

ideally, i'd combine both subplots 1 projecting triangles onto axis z=0. know possible other variants of 2d plots, not triplot. possible want?

ps. heavily simplified version of actual implementation using right now, hence random scattering might seem bit weird.

i'm not expert, interesting problem. after doing poking around, think got close. made triangulation object manually , passed , z list of zeros plot_trisurf, , set triangles in right place on z=0.

import matplotlib.pyplot plt import matplotlib.tri tri mpl_toolkits.mplot3d import axes3d import random def f( x, y): if x + y < 1: homecoming 0 else: homecoming 1 x = [0, 1, 1, 0] y = [0, 0, 1, 1] tris = [[0, 1, 3], [1, 2,3]] z = [0] * 4 triv = tri.triangulation(x, y, tris) fig = plt.figure() ax = fig.add_subplot( 111, projection='3d') trip = ax.plot_trisurf( triv, z ) trip.set_facecolor('white') xs = [random.random() _ in range( 100)] ys = [random.random() _ in range( 100)] zs = [f(xs[i], ys[i]) in range( 100)] ax.scatter( xs, ys, zs) plt.show()

eta: added phone call set_facecolor on poly3dcollection create white rather follow colormap. can futzed desired effect...

python matplotlib plot triangulation mplot3d

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -