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 715435c

Browse filesBrowse files
committed
Merge pull request #6260 from discardthree/bug-docs-1702
Bug fix and general touch ups for hist3d_demo example closes #1702
2 parents 0423430 + 4340a91 commit 715435c
Copy full SHA for 715435c

File tree

Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed

‎examples/mplot3d/hist3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/hist3d_demo.py
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
'''
2+
Demo of a histogram for 2 dimensional data as a bar graph in 3D.
3+
'''
4+
15
from mpl_toolkits.mplot3d import Axes3D
26
import matplotlib.pyplot as plt
37
import numpy as np
48

59
fig = plt.figure()
610
ax = fig.add_subplot(111, projection='3d')
711
x, y = np.random.rand(2, 100) * 4
8-
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
12+
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
913

10-
elements = (len(xedges) - 1) * (len(yedges) - 1)
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'.
1118
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
19+
xpos = xpos.flatten('F')
20+
ypos = ypos.flatten('F')
21+
zpos = np.zeros_like(xpos)
1222

13-
xpos = xpos.flatten()
14-
ypos = ypos.flatten()
15-
zpos = np.zeros(elements)
23+
# Construct arrays with the dimensions for the 16 bars.
1624
dx = 0.5 * np.ones_like(zpos)
1725
dy = dx.copy()
1826
dz = hist.flatten()

0 commit comments

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