小编Sha*_*awn的帖子

在 matplotlib 轮廓图中同时使用 set_under 和 set_bad

我正在尝试生成一个 matplotlib 轮廓图,其中所有值都在白色(包括零)的指定值下,并且所有 nan 值(表示缺失的数据)都是黑色的。我似乎无法让 nan 值与低于/零值的颜色不同。问题的一个简化示例是:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

# Generate some random data for a contour plot
Z = np.random.rand(10,10)
Z[0:3,0:3] = np.nan # some bad values for set_bad
Z[0:3,7:10] = 0 # some zero values for set_under
x = np.arange(10)
y = np.arange(10)
X,Y = np.meshgrid(x, y)

# Mask the bad data:
Z_masked = np.ma.array(Z,mask=np.isnan(Z))

# Get the colormap and set the under and bad colors
colMap = …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

5
推荐指数
1
解决办法
3209
查看次数

标签 统计

matplotlib ×1

python ×1