Skip to content

Commit 5f8138b

Browse files
committed
new contourf plot
1 parent 79c6f5c commit 5f8138b

File tree

2 files changed

+6444
-361
lines changed

2 files changed

+6444
-361
lines changed

test/test_contourf.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,33 @@
22
#
33
import matplotlib.pyplot as plt
44
import numpy as np
5+
from scipy.stats import multivariate_normal
56

67
from helpers import assert_equality
78

89

910
def plot():
10-
delta = 0.8
11-
x = y = np.arange(-3.0, 3.01, delta)
12-
X, Y = np.meshgrid(x, y)
13-
Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
14-
Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
15-
Z = 10 * (Z1 - Z2)
16-
levels = [-2, -1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3, 0.6, 0.9, 1.2, 1.5]
11+
mean = np.array([1, 1])
12+
cov = np.eye(2)
13+
nbins = 5
14+
1715
fig = plt.figure()
18-
CS = plt.contourf(X, Y, Z, 10, levels=levels)
19-
plt.contour(CS, levels=levels, colors="r")
16+
ax = plt.gca()
17+
18+
x_max = 2
19+
x_min = 0
20+
y_max = 2
21+
y_min = 0
22+
23+
xi, yi = np.mgrid[x_min:x_max:nbins * 1j, y_min:y_max:nbins * 1j]
24+
pos = np.empty(xi.shape + (2,))
25+
pos[:, :, 0] = xi
26+
pos[:, :, 1] = yi
27+
zi = multivariate_normal(mean, cov, allow_singular=True, seed=0).pdf(pos)
28+
ax.contourf(xi, yi, zi, 250)
29+
30+
ax.set_xlim(x_min, x_max)
31+
ax.set_ylim(y_min, y_max)
2032
return fig
2133

2234

0 commit comments

Comments
 (0)