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

Skip to content

Commit 4340a91

Browse files
committed
Fix bin range and tidy up comments.
1 parent 9b9ed32 commit 4340a91

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/mplot3d/hist3d_demo.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Note: np.meshgrid produces arrays in (ny, nx), so flatten is called with 'F'.
2-
# For numpy >= 1.7, this can be avoided by calling meshgrid with indexing='ij'.
1+
'''
2+
Demo of a histogram for 2 dimensional data as a bar graph in 3D.
3+
'''
34

45
from mpl_toolkits.mplot3d import Axes3D
56
import matplotlib.pyplot as plt
@@ -8,13 +9,18 @@
89
fig = plt.figure()
910
ax = fig.add_subplot(111, projection='3d')
1011
x, y = np.random.rand(2, 100) * 4
11-
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
12+
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
1213

14+
# Construct arrays for the anchor positions of the 16 bars.
15+
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten xpos,
16+
# ypos in column-major order. For numpy >= 1.7, we could instead call meshgrid
17+
# with indexing='ij'.
1318
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
1419
xpos = xpos.flatten('F')
1520
ypos = ypos.flatten('F')
1621
zpos = np.zeros_like(xpos)
1722

23+
# Construct arrays with the dimensions for the 16 bars.
1824
dx = 0.5 * np.ones_like(zpos)
1925
dy = dx.copy()
2026
dz = hist.flatten()

0 commit comments

Comments
 (0)