繁体   English   中英

用纯色填充轮廓部分

[英]Fill section of contour with solid color

我有一个等高线图,其中一些z值等于零。 我想以此将所有这些值着色为特定的颜色

不完整

为此(MS Paint模拟)。

完成

我该怎么做呢? 库中是否有某些功能可以使我做到这一点?

看看matplotlib轮廓图和颜色图演示。 在等高线图演示的最后一个示例中,您可以为等高线图指定一个颜色图,如下所示

plt.figure()
# plots a bunch of colours
im = plt.imshow(Z, interpolation='bilinear', origin='lower',
                cmap=cm.gray, extent=(-3, 3, -2, 2))

# plot the contour lines 
levels = np.arange(-1.2, 1.6, 0.2)
CS = plt.contour(Z, levels,
                 origin='lower',
                 linewidths=2,
                 extent=(-3, 3, -2, 2))

如果要将某些区域保留为白色/未填充,则需要定义自己的颜色图。 颜色图只是将数值映射到颜色的dict

https://matplotlib.org/examples/pylab_examples/contour_demo.html

https://matplotlib.org/examples/pylab_examples/custom_cmap.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM