matplotlib 如何表示和图像的灰度对应的过密区域,虚线轮廓的欠密区域

thtygnil  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(96)


的数据
这是用对数表示的密度场(灰度对应过密区域,虚线轮廓对应欠密区域,实线轮廓表示平均密度)
在我的数据中,我展示了这样的热图




我还尝试在plot中使用contour(),
看起来不太好。如果我想显示像第一个一样的Map,我应该使用什么函数?

gzszwxb4

gzszwxb41#

下面是一个基于herehere的基本示例:

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()

字符串
这给出:


的数据

相关问题