我不熟悉python的matplotlib,必须绘制一些东西,显示图像并在下面添加文本。 到目前为止,我所做的是(简化示例):
from matplotlib import pyplot as plt
from matplotlib import image as img
fig = plt.figure()
pic = img.imread("image path")
ax1 = fig.add_subplot(121)
ax1.plot()
ax1.set_yticks([0, 1, 2, 3, 4, 5])
ax1.set_xticks([0, 1, 2, 3, 4, 5])
ax1.annotate("Text", xy=(0, -0.12), xycoords="axes fraction")
ax1.annotate("More text", xy=(0, -0.17), xycoords="axes fraction")
ax1.annotate("Even more text", xy=(0, -0.22), xycoords="axes fraction")
ax1.annotate("1", xy=(1, -0.12), xycoords="axes fraction", ha="right")
ax1.annotate("2", xy=(1, -0.17), xycoords="axes fraction", ha="right")
ax1.annotate("3", xy=(1, -0.22), xycoords="axes fraction", ha="right")
ax2 = fig.add_subplot(122)
ax2.imshow(pic)
ax2.axis("off")
ax2.annotate("Text", xy=(0, -0.1), xycoords="axes fraction")
ax2.annotate("More text", xy=(0, -0.2), xycoords="axes fraction")
ax2.annotate("Even more text", xy=(0, -0.3), xycoords="axes fraction")
ax2.annotate("1", xy=(1, -0.1), xycoords="axes fraction", ha="right")
ax2.annotate("2", xy=(1, -0.2), xycoords="axes fraction", ha="right")
ax2.annotate("3", xy=(1, -0.3), xycoords="axes fraction", ha="right")
plt.subplots_adjust(bottom=0.18)
plt.show()
问题:我希望两个子图都垂直对齐,这样两个子图下面的文本也垂直对齐。但是图像总是出现在“中间”(red pic in the middle of left plot and not same x axis)。是否有可能将图像放在绘图的x轴上,或者是否有人知道更好的方法在两个子绘图下面添加文本(无注释)
我尝试的是:
Blended transformations
Ref在我的代码中用于根据需要对齐两个轴上的注释项输出曲线图:
相关问题 更多 >
编程相关推荐