为什么我的颜色栏上有线条? [英] why does my colorbar have lines in it?

查看:86
本文介绍了为什么我的颜色栏上有线条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:由于这似乎是一个受欢迎的帖子,因此以下解决方案似乎对我来说效果很好.谢谢@gazzar和@mfra.

Edit: Since this seems to be a popular post, here's the solution that seems to be working well for me. Thanks @gazzar and @mfra.

cbar.solids.set_rasterized(True)
cbar.solids.set_edgecolor("face")


有人知道为什么我的颜色条中似乎有线条吗?还是为什么颜色过渡不平滑?显然,我正在使用底图,但这没关系,因为所有这些都是在AFAICT之下进行的matplotlib调用.我创建地图时所做的操作类似


Does anyone know why my colorbar has what appear to be lines in it? Or rather why is the color transition not smooth? I'm using basemap, obviously, but that shouldn't matter since it's all matplotlib calls under the hood AFAICT. I create the map doing something like

grays = plt.cm.get_cmap("Grays")
sc = mymap.scatter(xpoints, ypoints, s=sizes, c=color_values, cmap=grays, alpha=.75,
                   marker="o", zorder=10, vmin=0, vmax=1)
cbar = mymap.colorbar(sc, drawedges=True, location="bottom")

我尝试了不使用alpha和不使用alpha的情况,结果是相同的.也许是因为我的color_values数组不够好吗?我可以在某处设置映射到颜色栏的基础值吗?我没有看到如何,也没有在其他地方看到这个问题.即,我可以复制matplotlib show_colorbars示例,而不会出现此问题.

I tried without and without alpha and the result was the same. Maybe it is because my color_values array is not fine enough? Can I set the underlying values that are mapped to the colorbar somewhere? I don't see how, and I don't see this problem elsewhere. Ie., I can replicate the matplotlib show_colorbars example without this problem.

推荐答案

如果创建矢量图形,是否尝试过此操作(取自

In case you create vector graphics, have you tried this (taken from http://matplotlib.org/api/pyplot_api.html?highlight=colorbar#matplotlib.pyplot.colorbar):

众所周知,某些矢量图形查看器(svg和pdf)在颜色条的各段之间呈现白色间隙.这是由于查看器中的错误(不是matplotlib)所致.作为解决方法,可以使用重叠的段来呈现颜色条: /p>

"It is known that some vector graphics viewer (svg and pdf) renders white gaps between segments of the colorbar. This is due to bugs in the viewers not matplotlib. As a workaround the colorbar can be rendered with overlapping segments:

cbar = colorbar()
cbar.solids.set_edgecolor("face")
draw()

但是,这在其他情况下也会带来负面影响.特别是对于半透明图像(alpha <1)和颜色条扩展名,并且默认情况下未启用(请参见问题1188)."

However this has negative consequences in other circumstances. Particularly with semi transparent images (alpha < 1) and colorbar extensions and is not enabled by default see (issue #1188)."

这篇关于为什么我的颜色栏上有线条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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