2

I am trying to plot a figure with 8 rows of data. And I use the following line of code.

fig, ax = plt.subplots(9, 1, sharex=True, squeeze=True, figsize=(12, 18))

For this code, I have successfully produce 8 rows of data, with the same x-axis (sharex=True) and the same row heights. However, I want the just the first row of data to be of a different row height only (still same x-axis) and all.

How do I go about doing this?

Thank you fin advance for your kind assistance in helping me.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Sofyan Sahrom
  • 395
  • 1
  • 4
  • 8
  • @ImportanceOfBeingErnest. Apologies for it being a duplicate, but I really cannot find the answer at the suggested thread. Using GridSpec changes the column size, but what I want is row 1 of a certain hieght, row 2 of a different height etc. Can you please guide me to the right thread? I am sincerly asking for help and not trying to be lazy and not searching the stack overflow. – Sofyan Sahrom Oct 14 '18 at 05:46
  • Sorry, I thought that was obvious. I reopened and gave an answer. – ImportanceOfBeingErnest Oct 14 '18 at 12:46

1 Answers1

6

Similar to this answer where different widths of subplots can be achieved via the width_ratios keyword of the gridspec, you may use the height_ratios to achieve different heights of the subpplots.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(5, 1, sharex=True, squeeze=True, 
                       gridspec_kw = {'height_ratios':[1,2,5,2,3]})

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712