Skip to content

Commit

Permalink
Merge pull request #6260 from discardthree/bug-docs-1702
Browse files Browse the repository at this point in the history
Bug fix and general touch ups for hist3d_demo example

closes #1702
  • Loading branch information
tacaswell committed Apr 2, 2016
1 parent 860fdfe commit a8851dd
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions examples/mplot3d/hist3d_demo.py
@@ -1,18 +1,26 @@
'''
Demo of a histogram for 2 dimensional data as a bar graph in 3D.
'''

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

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

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

xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)
# Construct arrays with the dimensions for the 16 bars.
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
Expand Down

0 comments on commit a8851dd

Please sign in to comment.