import matplotlib.pyplot as plt
import matplotlib.colors as colors
from matplotlib import colormaps
import numpy as np
fig, ax = plt.subplots()
delta = 0.01
x = y = np.arange(-3.0, 3.01, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
# get the mean of Z (say the density)
md = np.mean(Z)
# first create a masked version of Z to plot as a grey scale image
overdense = Z.copy()
overdense[Z < md] = np.ma.masked
ax.imshow(
overdense,
interpolation="bilinear",
origin="lower",
extent=[x[0], x[-1], y[0], y[-1]],
cmap=colormaps["Greys"],
norm=colors.Normalize(vmin=md, vmax=np.max(Z)),
)
# over plot the contours for the over dense and underdense regions
# (I'm defining the underdense contours to be 0.1 less than the mean density)
ax.contour(x, y, Z, levels=[md - 0.1, md], colors="k")
plt.show()
1条答案
按热度按时间gzszwxb41#
下面是一个基于here和here的基本示例:
字符串
这给出:
的数据