Getting the same subplot size using matplotlib imshow and scatter

后端 未结 3 963

I am trying to plot an image (using matplotlib.imshow) and a scatter plot within the same figure. When trying this, the image appears smaller than the scatter p

3条回答
  •  渐次进展
    2020-12-09 03:56

    I had the same problem and asked a very similar question in SO. The solution proposed by @ImportanceOfBeingErnest worked like a charm for me, but for completeness, I'd like to mention a pretty simple workaround I was suggested to apply (credit to @Yilun Zhang) before my question was marked as an exact duplicate of this one:

    The problem is that the plot region height is too large and this is leaving empty place in the image.

    If you change your code to:

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))
    

    then you get the desired outcome:

提交回复
热议问题