设置Matplotlib颜色条大小以匹配图形 [英] Set Matplotlib colorbar size to match graph
本文介绍了设置Matplotlib颜色条大小以匹配图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在这样的imshow图形上获得与图形高度相同的颜色条,而不是事后使用Photoshop。如何获得匹配的高度?
I cannot get the colorbar on imshow graphs like this one to be the same height as the graph, short of using Photoshop after the fact. How do I get the heights to match?
推荐答案
您可以使用matplotlib轻松完成此操作 AxisDivider 。
You can do this easily with a matplotlib AxisDivider.
链接页面中的示例也可以在不使用子图的情况下工作:
The example from the linked page also works without using subplots:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
plt.figure()
ax = plt.gca()
im = ax.imshow(np.arange(100).reshape((10,10)))
# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.05 inch.
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(im, cax=cax)
这篇关于设置Matplotlib颜色条大小以匹配图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文