Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc9e1bd

Browse files
committed
Cleaning up example mplot3d/bars3d_demo
1 parent 59f2fb3 commit cc9e1bd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

examples/mplot3d/bars3d_demo.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
'''
2+
Demonstrates making a 3D plot which has 2D bar graphs projected onto
3+
planes y=0, y=1, etc.
4+
'''
5+
16
from mpl_toolkits.mplot3d import Axes3D
27
import matplotlib.pyplot as plt
38
import numpy as np
49

510
fig = plt.figure()
611
ax = fig.add_subplot(111, projection='3d')
7-
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
12+
13+
colors = ['r', 'g', 'b', 'y']
14+
yticks = [3, 2, 1, 0]
15+
for c, k in zip(colors, yticks):
16+
# Generate the random data for the y=k 'layer'.
817
xs = np.arange(20)
918
ys = np.random.rand(20)
1019

11-
# You can provide either a single color or an array. To demonstrate this,
12-
# the first bar of each set will be colored cyan.
20+
# You can provide either a single color or an array with the same length as
21+
# xs and ys. To demonstrate this, we color the first bar of each set cyan.
1322
cs = [c] * len(xs)
1423
cs[0] = 'c'
15-
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
24+
25+
# Plot the bar graph given by xs and ys on the plane y=k with 80% opacity.
26+
ax.bar(xs, ys, zs=k, zdir='y', color=cs, alpha=0.8)
1627

1728
ax.set_xlabel('X')
1829
ax.set_ylabel('Y')
1930
ax.set_zlabel('Z')
2031

32+
# On the y axis let's only label the discrete values that we have data for.
33+
ax.set_yticks(yticks)
34+
2135
plt.show()

0 commit comments

Comments
 (0)