How to show multiple images in one figure?

前端 未结 2 1878
予麋鹿
予麋鹿 2021-01-01 10:20

I use Python lib matplotlib to plot functions, and I know how to plot several functions in different subplots in one figure, like this one,

相关标签:
2条回答
  • 2021-01-01 11:02

    The documentation provides an example (about three quarters of the way down the page):

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np
    fig = plt.figure()
    a=fig.add_subplot(1,2,1)
    img = mpimg.imread('../_static/stinkbug.png')
    lum_img = img[:,:,0]
    imgplot = plt.imshow(lum_img)
    a.set_title('Before')
    plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation ='horizontal')
    a=fig.add_subplot(1,2,2)
    imgplot = plt.imshow(lum_img)
    imgplot.set_clim(0.0,0.7)
    a.set_title('After')
    plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation='horizontal')
    
    # ---------------------------------------
    # if needed inside the application logic, uncomment to show the images
    # plt.show()
    

    Basically, it's the same as you do normally with creating axes with fig.add_subplot...

    0 讨论(0)
  • 2021-01-01 11:02

    Simple python code to plot subplots in a figure;

    rows=2
    cols=3
    fig, axes = plt.subplots(rows,cols,figsize=(30,10))
    plt.subplots_adjust(wspace=0.1,hspace=0.2)
    features=['INDUS','RM', 'AGE', 'DIS','PTRATIO','MEDV']
    plotnum=1
    for idx in features:
        plt.subplot(rows,cols,plotnum)
        sns.distplot(data[idx])
        plotnum=plotnum+1
    plt.savefig('subplots.png')
    

    go through below link for more detail https://exploredatalab.com/how-to-plot-multiple-subplots-in-python-with-matplotlib/

    0 讨论(0)
提交回复
热议问题