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

Skip to content

Commit d50bf9a

Browse files
committed
DOC: add gallery example
1 parent 29e3a8d commit d50bf9a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
========================================
3+
3D Histogram with hexagonal bins
4+
========================================
5+
6+
Demonstrates visualising a 3D density map of data using hexagonal tessellation.
7+
"""
8+
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
from matplotlib.cbook import hexbin
13+
14+
# Fixing random state for reproducibility
15+
np.random.seed(42)
16+
17+
# Generate samples from mltivariate Gaussian
18+
# Parameters
19+
mu = (0, 0)
20+
sigma = ([0.8, 0.3],
21+
[0.3, 0.5])
22+
n = 10_000
23+
gridsize = 15
24+
# draw samples
25+
xy = np.random.multivariate_normal(mu, sigma, n)
26+
# histogram samples with hexbin
27+
xyz, (xmin, xmax), (ymin, ymax), (nx, ny) = hexbin(*xy.T, gridsize=gridsize,
28+
mincnt=3)
29+
# compute bar cross section size
30+
dxy = np.array([(xmax - xmin) / nx, (ymax - ymin) / ny / np.sqrt(3)]) * 0.95
31+
32+
# plot
33+
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
34+
ax.hexbar3d(*xyz, dxy, cmap='plasma')
35+
ax.set(xlabel='x', ylabel='y', zlabel='z')
36+
37+
plt.show()

0 commit comments

Comments
 (0)