0

I have a chart in matplotlib which uses two subplots. Code is as follows:

# Chart

chart_data['whisker'] = chart_data['high'] - chart_data['low']

%matplotlib inline

fig, axs = plt.subplots(2, 1, sharex=True, figsize=(20, 15))
#fig.figure(num=None, figsize=(8, 6))
mpl.pyplot.figure(num=1, figsize=(16, 9))
fig.subplots_adjust(hspace=0)

#mpl.rcParams['figure.figsize'] = [16, 9]

axs[0].bar(chart_data['timestamp'], chart_data['whisker'], width=0.0004, bottom=chart_data['low'], color='b')
axs[1].bar(chart_data['timestamp'], chart_data['volume'], width=0.002)

axs[0].grid(b=None, which='both', axis='both')
axs[1].grid(b=None, which='both', axis='both')

axs[0].set_axisbelow(True)
axs[1].set_axisbelow(True)
plt.gcf().autofmt_xdate()

plt.show()
chart_data.head()

Chart data is as follows:

data

Chart result is as follows:

Subplots

How can I make below subplot to have one third the height it has now? Or specify a given height. I have tried:

from matplotlib.pyplot import figure
figure(num=1, figsize=(8, 6))

whitout success

M.E.
  • 4,955
  • 4
  • 49
  • 128
  • In which units do you want to specify the subplot height? And how large should the other subplot be? – ImportanceOfBeingErnest Jul 12 '19 at 18:42
  • @ImportanceOfBeingErnest I am unsure of what units I am using when `figsize=(20, 15)` is specified (which changes the width and height of the whole chart). I would like to specify in the same units as `figsize=(20, 15)`. The other plot shall keep its height. I am looking more to have a relationship between heights than specific units and heights. – M.E. Jul 12 '19 at 19:10
  • If this is only about relative size of the two subplots you can use `height_ratios` like `plt.subplots(..., gridspec_kw=dict(height_ratios=[3,1]))`. – ImportanceOfBeingErnest Jul 12 '19 at 19:12
  • @ImportanceOfBeingErnest Thanks that helps – M.E. Jul 12 '19 at 23:11
  • @ImportanceOfBeingErnest feel free to answer the question so I can select it as the right one. – M.E. Jul 12 '19 at 23:24

0 Answers0