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

Commit b207320

Browse filesBrowse files
committed
Cleaning up example mplot3d/2dcollections3d_demo.
1 parent f859b74 commit b207320
Copy full SHA for b207320

File tree

Expand file treeCollapse file tree

1 file changed

+23
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-4
lines changed
+23-4Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1+
'''
2+
Demonstrates using ax.plot's zdir keyword to plot 2D scatterplot data on
3+
selective axes of a 3D plot.
4+
'''
5+
16
from mpl_toolkits.mplot3d import Axes3D
27
import numpy as np
38
import matplotlib.pyplot as plt
49

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

13+
# Plot a sin curve using the x and y axes.
814
x = np.linspace(0, 1, 100)
915
y = np.sin(x * 2 * np.pi) / 2 + 0.5
10-
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z')
16+
ax.plot(x, y, zs=0, zdir='z', label='curve in (x,y)')
1117

18+
# Plot scatterplot data (20 2D points per colour) on the x and z axes.
1219
colors = ('r', 'g', 'b', 'k')
20+
x = np.random.sample(20*len(colors))
21+
y = np.random.sample(20*len(colors))
22+
c_list = []
1323
for c in colors:
14-
x = np.random.sample(20)
15-
y = np.random.sample(20)
16-
ax.scatter(x, y, 0, zdir='y', c=c)
24+
c_list.append([c]*20)
25+
# By using zdir='y', the y value of these points is fixed to the zs value 0
26+
# and the (x,y) points are plotted on the x and z axes.
27+
ax.scatter(x, y, zs=0, zdir='y', c=c_list, label='points in (x,z)')
1728

29+
# Make legend, set axes limits and labels
1830
ax.legend()
1931
ax.set_xlim3d(0, 1)
2032
ax.set_ylim3d(0, 1)
2133
ax.set_zlim3d(0, 1)
34+
ax.set_xlabel('X')
35+
ax.set_ylabel('Y')
36+
ax.set_zlabel('Z')
37+
38+
# Customize the view angle so it's easier to see that the scatter points lie
39+
# on the plane y=0
40+
ax.view_init(elev=20., azim=-35)
2241

2342
plt.show()

0 commit comments

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