Files
python-VM/bayes-learning/test.py

22 lines
540 B
Python

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors
x = np.linspace(-3, 3)
X, Y = np.meshgrid(x, x)
Z = np.exp(-(X**2 + Y**2))
fig, (ax, ax2) = plt.subplots(ncols=2)
colors = ["red", "orange", "gold", "limegreen", "k",
"#550011", "purple", "seagreen"]
ax.set_title("contour with color list")
contour = ax.contourf(X, Y, Z, colors=colors)
ax2.set_title("contour with colormap")
cmap = matplotlib.colors.ListedColormap(colors)
contour = ax2.contourf(X, Y, Z, cmap=cmap)
fig.colorbar(contour)
plt.show()