Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b846ea commit 6787135Copy full SHA for 6787135
8 files changed
examples/mplot3d/contour.py
@@ -0,0 +1,12 @@
1
+from mpl_toolkits.mplot3d import axes3d
2
+import pylab
3
+import random
4
+
5
+fig = pylab.figure()
6
+ax = axes3d.Axes3D(fig)
7
+X, Y, Z = axes3d.get_test_data(0.05)
8
+cset = ax.contour3D(X, Y, Z)
9
+ax.clabel(cset, fontsize=9, inline=1)
10
11
+pylab.show()
12
examples/mplot3d/contourf.py
+cset = ax.contourf3D(X, Y, Z)
examples/mplot3d/polys.py
@@ -0,0 +1,31 @@
+from mpl_toolkits.mplot3d import Axes3D
+from matplotlib.collections import PolyCollection
+from matplotlib.colors import colorConverter
+import numpy as np
+ax = Axes3D(fig)
+cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6)
13
+xs = np.arange(0, 10, 0.4)
14
+verts = []
15
+zs = [0.0, 1.0, 2.0, 3.0]
16
+for z in zs:
17
+ ys = [random.random() for x in xs]
18
+ ys[0], ys[-1] = 0, 0
19
+ verts.append(zip(xs, ys))
20
21
+poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'),
22
+ cc('y')])
23
+poly.set_alpha(0.7)
24
+ax.add_collection(poly, zs=zs, dir='y')
25
26
+ax.set_xlim(0, 10)
27
+ax.set_ylim(-1, 4)
28
+ax.set_zlim(0, 1)
29
30
31
examples/mplot3d/scatter.py
@@ -0,0 +1,21 @@
+n = 100
+for c, zl, zh in [('r', -50, -25), ('b', -30, -5)]:
+ xs, ys, zs = zip(*
+ [(random.randrange(23, 32),
+ random.randrange(100),
+ random.randrange(zl, zh)
+ ) for i in range(n)])
+ ax.scatter3D(xs, ys, zs, c=c)
+ax.set_xlabel('X Label')
+ax.set_ylabel('Y Label')
+ax.set_zlabel('Z Label')
examples/mplot3d/surface.py
@@ -0,0 +1,16 @@
+X = np.arange(-5, 5, 0.5)
+Y = np.arange(-5, 5, 0.5)
+X, Y = np.meshgrid(X, Y)
+R = np.sqrt(X**2 + Y**2)
+Z = np.sin(R)
+ax.plot_surface(X, Y, Z, rstride=1, cstride=1, color='forestgreen')
examples/mplot3d/wire.py
+ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
lib/mpl_toolkits/mplot3d/__init__.py
@@ -0,0 +1 @@
+from axes3d import Axes3D
lib/mpl_toolkits/mplot3d/axes3d.py
@@ -539,6 +539,9 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
539
rstride = kwargs.pop('rstride', 10)
540
cstride = kwargs.pop('cstride', 10)
541
542
+ color = kwargs.pop('color', 'b')
543
+ color = np.array(colorConverter.to_rgba(color))
544
545
polys = []
546
boxes = []
547
for rs in np.arange(0,rows-1,rstride):
@@ -567,8 +570,10 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
567
570
shade.append(np.dot(n,[-1,-1,0.5]))
568
571
lines.append((box[0],n+box[0]))
569
572
- color = np.array([0,0,1,1])
- norm = Normalize(min(shade),max(shade))
573
+ shade = np.array(shade)
574
+ mask = ~np.isnan(shade)
575
+ norm = Normalize(min(shade[mask]), max(shade[mask]))
576
577
colors = [color * (0.5+norm(v)*0.5) for v in shade]
578
for c in colors: c[3] = 1
579
polyc = art3d.Poly3DCollection(polys, facecolors=colors, *args, **kwargs)
0 commit comments