Plotting images side by side using matplotlib

后端 未结 5 1120
难免孤独
难免孤独 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 10:05

    You are plotting all your images on one axis. What you want ist to get a handle for each axis individually and plot your images there. Like so:

    fig = plt.figure()
    ax1 = fig.add_subplot(2,2,1)
    ax1.imshow(...)
    ax2 = fig.add_subplot(2,2,2)
    ax2.imshow(...)
    ax3 = fig.add_subplot(2,2,3)
    ax3.imshow(...)
    ax4 = fig.add_subplot(2,2,4)
    ax4.imshow(...)
    

    For more info have a look here: http://matplotlib.org/examples/pylab_examples/subplots_demo.html

    For complex layouts, you should consider using gridspec: http://matplotlib.org/users/gridspec.html

提交回复
热议问题