从色条方法的matplotlib命令摘要中,我知道关键字参数orientation := 'horizontal' | 'vertical'
作为一个参数分别在绘图下面放置一个水平条,或者在其右侧放置一个垂直条。
然而,在我的情况下,我宁愿把颜色条放在默认的另一边(不要太多的摆弄.(如有可能)。
我怎么能编码这个?我是不是漏掉了一些明显的特征?
发布于 2016-05-17 13:39:21
我认为最简单的方法是确保颜色条在自己的轴上。您可以从这个示例中进行调整:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
axp = ax.imshow(np.random.randint(0, 100, (100, 100)))
# Adding the colorbar
cbaxes = fig.add_axes([0.1, 0.1, 0.03, 0.8]) # This is the position for the colorbar
cb = plt.colorbar(axp, cax = cbaxes)
plt.show()
其结果是:
发布于 2020-04-07 14:52:46
我已经找到了另一种避免手动编辑轴位置的方法,而是允许您使用location关键字(最初从这里中改编的方法)将颜色条链接到现有的绘图轴。
location参数用于引用列表中多个轴的彩色条(如果只给出一个轴,则会抛出一个错误),但是如果您只将一个轴放在列表中,它将允许您使用参数。可以使用以下代码作为示例:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
axp = ax.imshow(np.random.randint(0, 100, (100, 100)))
cb = plt.colorbar(axp,ax=[ax],location='left')
plt.show()
这就产生了这个情节:
https://stackoverflow.com/questions/37280557
复制相似问题