简体   繁体   English

用纯色填充轮廓部分

[英]Fill section of contour with solid color

I have a contour plot with some z values equal to zero. 我有一个等高线图,其中一些z值等于零。 I want to shade all these values a particular color, from this 我想以此将所有这些值着色为特定的颜色

不完整

to this (MS Paint mock-up). 为此(MS Paint模拟)。

完成

How can I go about doing so? 我该怎么做呢? Is there some feature in the library that will allow me to do this? 库中是否有某些功能可以使我做到这一点?

Have a look at the matplotlib contourplot and colormap demos. 看看matplotlib轮廓图和颜色图演示。 From the contour plot demo's last example, you can specify a colour map for the contour plot as follows 在等高线图演示的最后一个示例中,您可以为等高线图指定一个颜色图,如下所示

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

you'll need to define your own color map if you want to leave some regions white/unfilled. 如果要将某些区域保留为白色/未填充,则需要定义自己的颜色图。 The colormap is just a dict that maps numeric values to colours 颜色图只是将数值映射到颜色的dict

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

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

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

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