当Alpha不为1时,Pyplot pcolormesh感到困惑 [英] Pyplot pcolormesh confused when alpha not 1

查看:82
本文介绍了当Alpha不为1时,Pyplot pcolormesh感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pyplot出色的绘图能力上遇到了一些困难.我已经选择了自己的色彩图

I am having some difficulty with pyplot's awesome drawing abilities. I have selected my very own colormap

n = 6
map = matplotlib.cm.get_cmap('Dark2')
cmap = colors.ListedColormap([(0,0,0,0)] + [[map(i * 1.0 / n)[j] for j in range(3)] + [0.2] for i in range(1, n + 1)])

这基本上只是Dark2颜色图,离散为n个值(在我的情况下为6个),零值映射为纯白色.但是,主要区别在于,我的自定义颜色图的alpha值设置为0.2,而不是默认的1.

This is basically just the Dark2 colormap, discretized to n (in my case 6) values with the zero value mapping to pure white. The main difference, however, is that the alpha values for my custom colormap are set to 0.2, not 1 as is default.

问题是,当我使用此图进行绘制时,例如

The problem is that when I plot something using this, like

plt.pcolormesh(np.random.rand(10,10), cmap = cmapInv)

结果是这样的:

这看起来已经足够好了,但是您可以清楚地看到,每个框周围都有一个非常细的边框,与框的颜色相同,但是alpha设置为1.

This looks nice enough, but you can clearly see that around each box, there is a very thin border of the same color as the box but with alpha set to 1.

如评论中所建议,这些边界的原因可能在两个框之间重叠.

As suggested in the comments, the cause of these borders is probably overlap between the boxes.

有办法清理吗?

推荐答案

在此期间,作为一个较小的解决方法,我发现您可以通过弄乱edgecolorlinewidth属性来使图像更接近所需的图像.例如,对pcolormesh使用以下输入:

As a minor workaround in the meantime, I found you can get the image closer to what you want by messing with the edgecolor and linewidth attributes. For example, using the following input to pcolormesh:

    plt.pcolormesh(np.random.rand(10,10), cmap = cmapInv, edgecolor=(1.0, 1.0, 1.0, 0.3), linewidth=0.0015625)

输出以下图像:

这篇关于当Alpha不为1时,Pyplot pcolormesh感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆