How could I arrange multiple pyplot figures in a kind of layout?

前端 未结 1 790
北海茫月
北海茫月 2021-02-08 14:23

I created a software to do signal analyses. There are multiple functions, and each finally display a complex figure containing labels, plot, axhspan, axvspan etc... Usually, the

1条回答
  •  情歌与酒
    2021-02-08 15:16

    You may combine several plots with matplotlib.pyplot.subplot. For more control on the layout, check out the GridSpec.

    Edit: As requested, a short example from the linked tutorial:

    A gridspec instance provides array-like (2d or 1d) indexing that returns the SubplotSpec instance. For, SubplotSpec that spans multiple cells, use slice.

    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec
    gs = gridspec.GridSpec(3, 3)
    ax1 = plt.subplot(gs[0, :])
    ax2 = plt.subplot(gs[1,:-1])
    ax3 = plt.subplot(gs[1:, -1])
    ax4 = plt.subplot(gs[-1,0])
    ax5 = plt.subplot(gs[-1,-2])
    

    enter image description here

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