![](/img/trans.png)
[英]How to put a matplotlib figure and a seaborn figure into one combined matplotlib figure
[英]How to put the title at the bottom of a figure in matplotlib?
由于您没有使用 x 轴,您可以简单地将 xlabel 设置为标题,应该注意定位:
ax.set_xlabel('this really is a title disguised as an x label')
编辑:
尝试根据图形高度偏移标题,我希望这有效:
size = fig.get_size_inches()*fig.dpi # get fig size in pixels
ax.set_title('(a)', y=-size) # increase or decrease y as needed
这是一个小的python函数,可以绘制没有轴的图像。 每个子图像底部的标题。 images是一个长度为 n 的数组,其中包含内存中的图像, labels是一个长度为 n 的数组,带有相应的标题:
from matplotlib import pyplot
def plot_image_array_gray(images, labels):
for i in range(0, len(labels)):
ax = pyplot.subplot(1, len(labels), i + 1)
pyplot.axis('off')
pyplot.text(0.5, -0.1, labels[i], \
horizontalalignment='center', verticalalignment='center', \
transform=ax.transAxes)
pyplot.imshow(images[i], cmap=pyplot.cm.gray)
pyplot.tight_layout()
pyplot.show()
使用示例
# code to load image_a and image_b
# ...
plot_image_array_gray((image_a, image_b), ("(a)", "(b)"))
如果您使用 ax,请使用以下行,然后调整 'y' 的值。
ax.set_title('(d)',y=-0.2,pad=-14)
您可以调整 y 值,这里我使用“负”值,因为我希望我的标签位于子图中的图形底部。
我还没有检查什么是垫。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.