Resize a figure automatically in matplotlib

后端 未结 6 991
滥情空心
滥情空心 2021-01-31 02:05

Is there a way to automatically resize a figure to properly fit contained plots in a matplotlib/pylab image?

I\'m creating heatmap (sub)plots that differ in aspect rat

6条回答
  •  忘掉有多难
    2021-01-31 02:42

    you can try using axis('scaled')

    import matplotlib.pyplot as plt
    import numpy
    
    #some dummy images
    img1 = numpy.array([[.1,.2],[.3,.4]]) 
    img2 = numpy.array([[.1,.2],[.3,.4]])
    
    fig,ax = plt.subplots()
    ax.imshow(img1,extent=[0,1,0,1])
    ax.imshow(img2,extent=[2,3,0,1])
    ax.axis('scaled') #this line fits your images to screen 
    plt.show()
    

提交回复
热议问题