简体   繁体   English

Python 中有没有办法使用 matplotlib 并排显示两个图像?

[英]Is there a way in Python to display two images side by side in scale using matplotlib?

I'm trying to display two images side by side in scale.我正在尝试按比例并排显示两个图像。 This is the code:这是代码:

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 15))
ax1.imshow(bird_rescaled)
ax2.imshow(bird_resized)

Unfortunately I just managed to come to this result:不幸的是,我只是设法得出这个结果:

一只鸟的不同大小的图像 . .
What I'd like to have is two in-scale images side by side, kind of like this:我想要的是两个并排的按比例缩放的图像,有点像这样:

美丽的拼贴画

Is there some function argument I'm missing that could solve this?我缺少一些 function 参数可以解决这个问题吗?

As mentioned by @mozway , sharey=True helped solving this problem.正如@mozway提到的, sharey=True帮助解决了这个问题。
I modified the code in this way:我以这种方式修改了代码:

fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, sharex=True, figsize=(12, 6))
ax1.imshow(bird_rescaled)
ax2.imshow(bird_resized)

adding sharex=True so that now the result looks perfect.添加sharex=True这样现在的结果看起来很完美。 [I can't post images because I don't have at least 10 reputation:(] [我不能发布图片,因为我没有至少 10 个声誉:(]

I also changed the values passed to the figsize argument:我还更改了传递给figsize参数的值:
I wanted the images to be 6x6 so the total figure needed to be 12x6.我希望图像为 6x6,因此总图需要为 12x6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM