Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DOC Clean up on about half the Mplot3d examples #6303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 19, 2016
Prev Previous commit
Documentation and tweaks to polys3d_demo: add two extra zero vertices…
… instead of zeroing out the first and last elements of the random data
  • Loading branch information
TrishGillett committed Apr 16, 2016
commit ab0d48c5383219e84fe00106a1803d737838d032
47 changes: 33 additions & 14 deletions 47 examples/mplot3d/polys3d_demo.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
'''
Demonstrate how to create semi-transparent polygons which fill the space
under a line graph, creating a sort of 'jagged stained glass' effect.
'''

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
from matplotlib.colors import colorConverter
import matplotlib.pyplot as plt
import numpy as np


def cc(arg):
'''
Shorthand to convert 'named' colors to rgba format at 60% opacity.
'''
return colorConverter.to_rgba(arg, alpha=0.6)


def polygon_under_graph(xlist, ylist):
'''
Construct the vertex list which defines the polygon filling the space under
the (xlist, ylist) line graph. Assumes the xs are in ascending order.
'''
return [(xlist[0], 0.)] + list(zip(xlist, ylist)) + [(xlist[-1], 0.)]


fig = plt.figure()
ax = fig.gca(projection='3d')

# Make verts a list, verts[i] will be a list of (x,y) pairs defining polygon i
verts = []

def cc(arg):
return colorConverter.to_rgba(arg, alpha=0.6)
# Set up the x sequence
xs = np.linspace(0., 10., 26)

xs = np.arange(0, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:
# The ith polygon will appear on the plane y = zs[i]
zs = range(4)

for i in zs:
ys = np.random.rand(len(xs))
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
verts.append(polygon_under_graph(xs, ys))

poly = PolyCollection(verts, facecolors=[cc('r'), cc('g'), cc('b'),
cc('y')])
poly.set_alpha(0.7)
poly = PolyCollection(verts, facecolors=[cc('r'), cc('g'), cc('b'), cc('y')])
ax.add_collection3d(poly, zs=zs, zdir='y')

ax.set_xlabel('X')
ax.set_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
ax.set_xlim(0, 10)
ax.set_ylim(-1, 4)
ax.set_zlim(0, 1)

plt.show()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.