我可以在 matplotlib 中的绘图左侧放置一个垂直颜色条吗? [英] Can I place a vertical colorbar to the left of the plot in matplotlib?
本文介绍了我可以在 matplotlib 中的绘图左侧放置一个垂直颜色条吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自
From the matplotlib command summary for the colorbar method I am aware that the keyword argument orientation := 'horizontal' | 'vertical'
as a parameter places an horizontal bar underneath the plot or a vertical to the right of it respectively.
Yet, in my situation, I would rather place the colour bar at the opposite side of the default (without too much fiddling... if possible).
How could I code this? Am I missing some obvious feature?
解决方案
I think the easiest way is to make sure the colorbar is in its own axis. You can adapt from this example:
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()
which results in this:
这篇关于我可以在 matplotlib 中的绘图左侧放置一个垂直颜色条吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文