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

Skip to content

Commit 9b9ed32

Browse files
committed
Issue matplotlib#1702 transpose bugfix
1 parent 7f21cc5 commit 9b9ed32

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/mplot3d/hist3d_demo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +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'.
3+
14
from mpl_toolkits.mplot3d import Axes3D
25
import matplotlib.pyplot as plt
36
import numpy as np
@@ -7,12 +10,11 @@
710
x, y = np.random.rand(2, 100) * 4
811
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
912

10-
elements = (len(xedges) - 1) * (len(yedges) - 1)
1113
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
14+
xpos = xpos.flatten('F')
15+
ypos = ypos.flatten('F')
16+
zpos = np.zeros_like(xpos)
1217

13-
xpos = xpos.flatten()
14-
ypos = ypos.flatten()
15-
zpos = np.zeros(elements)
1618
dx = 0.5 * np.ones_like(zpos)
1719
dy = dx.copy()
1820
dz = hist.flatten()

0 commit comments

Comments
 (0)