|||
refer to: https://www.codenong.com/18191867/
是否可以像下面的图像那样以对数刻度显示颜色条级别?
这是一些可以实现的示例代码:
1 | import matplotlib.pyplot as plt |
我在Windows 7上将python 2.7.3与matplotlib 1.1.1一起使用。
您的颜色条已经具有对数刻度。
@nordev-我相信OP正在询问如何在颜色栏上设置刻度定位器和格式化程序,以便以规则的日志间隔显示标签。
@JoeKington嗯,我似乎想起来,他最初的问题中的OP希望将刻度线放在对数间距为lvls数组中给定的值上,但也许我只是误解了他的意思。 感谢您指出。
您可能可以使用matplotlib.colors.LogNorm()来执行类似于此答案的操作
我建议生成一个伪彩色条,如下所示(有关说明,请参见注释):
1 | import matplotlib.pyplot as plt |
这会给你这样的情节:
编辑
或者,在调用colorbar时使用新级别和spacing='proportional'选项之类的东西:
您将得到以下情节:
(仅更改了format,因为新的刻度不需要4位小数)
编辑2
如果您想自动生成类似我使用过的级别,可以考虑以下代码:
1 | levels = [] |
替换此行:
1 | lvls = np.logspace(0,4,20) |
用这些:
1 | lvls = np.linspace(1,10,5) |
替换此行:
1 | cbar = plt.colorbar(CF, ticks=lvls, format='%.4f') |
有了这个:
1 | cbar = plt.colorbar(CF, ticks=lvls, format='%.2f', spacing='proportional') |
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-19 21:30
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社