Plotting images side by side using matplotlib

后端 未结 5 1117
难免孤独
难免孤独 2020-12-23 09:36

I was wondering how I am able to plot images side by side using matplotlib for example something like this:

The closest I got is this:

5条回答
  •  半阙折子戏
    2020-12-23 09:56

    The problem you face is that you try to assign the return of imshow (which is an matplotlib.image.AxesImage to an existing axes object.

    The correct way of plotting image data to the different axes in axarr would be

    f, axarr = plt.subplots(2,2)
    axarr[0,0].imshow(image_datas[0])
    axarr[0,1].imshow(image_datas[1])
    axarr[1,0].imshow(image_datas[2])
    axarr[1,1].imshow(image_datas[3])
    

    The concept is the same for all subplots, and in most cases the axes instance provide the same methods than the pyplot (plt) interface. E.g. if ax is one of your subplot axes, for plotting a normal line plot you'd use ax.plot(..) instead of plt.plot(). This can actually be found exactly in the source from the page you link to.

提交回复
热议问题