0

I want to create a function that plots multiple rows of plot and the last row with multiple column of plots.

    fig = plt.figure()

    ax = plt.subplot(3,1,1)
    ax.plot(self.dfile['test'], label='test', marker='o', markersize=1, linestyle="", zorder=1)
    ax.set_ylabel('test')

    ax1 = plt.subplot(3,1,2)
    qt = self.do_something(self.dfile['foo'])
    ax1.plot(qt, label='foo', marker='x', markersize=1, linestyle="", zorder=1)
    ax1.hlines(y=1,xmin=0, xmax=len(qt),color='r', zorder=2, alpha=0.55, linewidth=0.8)
    ax1.set_ylabel('foobar')
    ax1.set_xlabel('Time (s)')

    ax2 = plt.subplot(3,1,3)
    x = self.dfile['foo'].value_counts().reset_index()

    x1 = self.dfile['foo'][0:150].value_counts().reset_index()
    x2 = self.dfile['foo'][150:300].value_counts().reset_index()
    x3 = self.dfile['foo'][300:450].value_counts().reset_index()
    x4 = self.dfile['foo'][450:600].value_counts().reset_index()

    ax2.scatter(x1['index'], x1['foo'], s=2)
    ax2.set_yticks([0, 10, 20, 30, 40])
    ax2.set_ylabel('Count')
    ax2.set_xlabel('some x label')
    #ax2.grid(linestyle='-', which='both')

    ax3 = plt.subplot(3,2,3)
    ax3.scatter(x2['index'], x2['foo'], s=2)
    ax3.set_yticks([0, 10, 20, 30, 40])
    ax3.set_ylabel('Count')
    ax3.set_xlabel('some x label')

    fig.tight_layout()
    plt.subplots_adjust(wspace=0, hspace=0.15)
    file_name = 'test.png'
    fig.savefig(OUTPUT_PATH + str(file_name), bbox_inches='tight', dpi=DPI, pad_inches=0.1)
    fig.clf()
    plt.close()

This is my attempt at it. I want to ensure that the last row multiple columns of plots. Here is an example

enter image description here

tandem
  • 2,040
  • 4
  • 25
  • 52
  • The question is a bit hard to understand. Which subplot are you expecting to be placed where exactly in the figure? – ImportanceOfBeingErnest Jan 05 '19 at 13:15
  • @ImportanceOfBeingErnest, provide an example – tandem Jan 05 '19 at 13:18
  • The image shows five axes, but you only have four in your code. That's why I don't know where you want to have which axes. – ImportanceOfBeingErnest Jan 05 '19 at 13:21
  • @ImportanceOfBeingErnest, the last row of plots need to have multiple columns. What I'm trying to achieve with my code is this. Create the first two rows of plots and split the last row into multiple subplots. – tandem Jan 05 '19 at 13:23
  • So the first subplot of the last row would be `ax2 = plt.subplot(3,3,1)`, the second, `ax3 = plt.subplot(3,3,2)`. In general this would all be explained in [this question](https://stackoverflow.com/questions/3584805/in-matplotlib-what-does-the-argument-mean-in-fig-add-subplot111). – ImportanceOfBeingErnest Jan 05 '19 at 13:46
  • @tandem: Have a look at [this](https://stackoverflow.com/questions/53978121/how-can-i-plot-four-subplots-with-different-colspans/53978336#53978336) answer. You can very easily modify the answer to get your task done. The link ImportanceOfBeingErnest gave is though really the best – Sheldore Jan 05 '19 at 13:47
  • @Bazingaa indeed! thanks – tandem Jan 05 '19 at 13:48

0 Answers0