我想生成一个由多个数组组成的绘图网格,具有正值和负值,具有对数刻度,共享相同的颜色条。
我已经实现了颜色条的共享部分(使用 ImageGrid 和常见的最大值和最小值),并且我知道在只有正值的情况下,我可以在 imshow 调用上使用 LogNorm() 获得对数刻度。但考虑到负值的存在,我需要一个对称对数刻度的颜色条。
I have found what would be the solution on https://stackoverflow.com/a/7741317/1101750 https://stackoverflow.com/a/7741317/1101750 , but running the sample code Yann provides gives me very different results, cleary wrong:
Reviewing the code, I'm not able to grasp what's going on.
除此之外,我发现在 Matplotlib 1.2 上,scale.SymmetricalLogScale.SymmetricalLogTransform 要求一个文档中未解释的新参数(linscale,查看其他转换的代码,我认为将其保留为 1 是安全的价值)。
最简单的解决方案是子类化 LogNorm 吗?
我过去使用过一个非常简单的方法来做到这一点,而不需要进行任何子类化。 matplotlib.colors.SymLogNorm 提供了您需要的大部分功能,但我发现有必要手动生成刻度线。请注意,此解决方案使用 matplotlib 1.3.0,我可能使用 1.2 中不可用的功能。
def imshow_symlog(my_matrix, vmin, vmax, logthresh=5):
img=imshow( my_matrix ,
vmin=float(vmin), vmax=float(vmax),
norm=matplotlib.colors.SymLogNorm(10**-logthresh) )
maxlog=int(np.ceil( np.log10(vmax) ))
minlog=int(np.ceil( np.log10(-vmin) ))
#generate logarithmic ticks
tick_locations=([-(10**x) for x in xrange(minlog,-logthresh-1,-1)]
+[0.0]
+[(10**x) for x in xrange(-logthresh,maxlog+1)] )
cb=colorbar(ticks=tick_locations)
return img,cb
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)