颜色条上的日志标签matplotlib [英] Log labels on colorbar matplotlib
本文介绍了颜色条上的日志标签matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对数的imshow图,创建了颜色条时,其轴标签和刻度线是对数的,但是由于值的范围很短(0-50),所以颜色条看起来像这样:
I have a logarithmic imshow figure, and when the colorbar is created, its axis labels and ticks are logarithmic, but because of the short range (0-50) of the values, the colorbar looks like this:
我希望它显示为沿轴间隔(对数间距)为0、5、10、20、50.
and I would like it to instead show as 0, 5, 10, 20, 50 spaced along the axis (logarithmic spacing).
我似乎无法使它正常工作.
I can't seem to get this to work.
感谢您的帮助.
推荐答案
使用 LogFormatter
类并将 labelOnlyBase
设置为 False
:>
Use the LogFormatter
class and set labelOnlyBase
to False
:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors
from matplotlib.ticker import LogFormatter
A = np.random.rand(50,50)*50
plt.imshow(A, norm=matplotlib.colors.LogNorm())
formatter = LogFormatter(10, labelOnlyBase=False)
cb = plt.colorbar(ticks=[1,5,10,20,50], format=formatter)
plt.show()
这篇关于颜色条上的日志标签matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文