使小值在 python 中的 matplotlib 颜色条上可见
我将颜色条与默认的“jet”贴图一起使用,并将其与“hexbin”一起使用。我的垃圾箱中的计数范围从 0 到大约 1500。问题是,某些六边形垃圾箱中的最小值在 1 到 10 之间,而某些垃圾箱的计数为数百个。这意味着在 jet 颜色图中,0 到 10 的范围显示为颜色 0,即它与计数为 0 的 bin 无法区分。我希望这些小值是可见的。如何使颜色图执行类似以下操作:确保大于或等于 N 的 bin 值具有“可见”,即与颜色图中的 0 bin 值不同?
谢谢。
I'm using colorbar with the default "jet" map and use that with "hexbin". I have counts in my bins that range from 0 to about 1500. The problem is that the smallest values in some hexagonal bins are between 1 and 10, while some bins have counts of hundreds. This means that in the jet colormap, the 0 to 10 range comes up as the color 0 -- i.e. it is indistinguishable from a bin with 0 counts. I'd like those small values to be visible. How can I make colormap do something like: make sure that the bin values greater than or equal to N have a "visible", meaning different from the 0 bin, value in the color map?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此外,还有
mincnt
选项用于设置 hexbin 中的最小计数,这会将所有小于此数字的 bin 留空。这使得在 jet 配色方案中很容易区分零和一计数。Also, there is the
mincnt
option to set the minimum count in hexbin, which leaves all bins with less than this number blank. This makes it very easy to distinguish between zero and one counts in the jet color scheme.一个快速修复方法可以尝试绘制
log(counts)
而不是在十六进制上绘制计数——这会扩展比例,从而压缩较高的计数而不会压缩较低的计数。但请注意,您必须在某个地方放置可视化的值是
log(counts)
而不是counts
,否则漫不经心的读者不可避免地会误解该图表。更好的方法可能是修改您正在使用的颜色图。
内置贴图或多或少从“0”颜色线性变化到“1”颜色。
为了使较低的值比较较高的值具有更多的颜色分布,您需要非线性颜色图。
为此,您可以尝试
matplotlib.colors
,特别是matplotlib.colors.LinearSegmentedColormap.from_list
(http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap.from_list)基本上,您输入“0”和“1”颜色(例如蓝色 - ->红色)和伽玛值。具有γ>1。 1.0 增加了量表下部的灵敏度。
如果还没有尝试过,但类似:
A quick fix could be try plotting
log(counts)
instead of counts on the hexbin -- this will spread the scale such that higher counts are compressed and lower counts are not.Note though, you'd have to put somewhere that the value being visualised is
log(counts)
notcounts
or else a casual reader would inariably misinterpret the graph.A better method might be to modify the colour map that you're using.
The in-built maps more or less change from the '0' colour to the '1' colour linearly.
In order to make lower values have more spread in colour than the higher values, you need a non-linear colour map.
To do this you might try
matplotlib.colors
, and in particularmatplotlib.colors.LinearSegmentedColormap.from_list
(http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap.from_list)Basically, you input the '0' and '1' colours (like blue-->red) and a gamma value. Having gamma > 1.0 increases sensitivity in the lower part of the scale.
If haven't tried, but something like: