I am having some trouble understanding the subplot concept. As I understand subplots are organized (number of rows, numbers of column, and the plot number or how many places the plot is taking)
I have this code:
from pandas import util
import pandas.util.testing as testing
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib as mpl
df = util.testing.makeDataFrame()
with mpl.rc_context(rc={'font.family': 'serif', 'font.weight': 'light', 'font.size': 12}):
fig = plt.figure(figsize= (12, 6))
ax = fig.add_subplot(2, 2, (1,2))
ax2 = ax.twinx()
df['A'].plot(ax=ax, color = 'g')
df['B'].plot(ax=ax2, color ='g')
fig.add_subplot(223)
df['C'].plot(color='r')
plt.axvline(x = 7, color = 'b', label = 'axvline - full height')
fig.add_subplot(2,2,4)
df = df.round(0)
ax3 = df['D'].plot(kind='bar')
ax3.legend( prop={'size': 6})
fig.tight_layout()
plt.show()
Which produces this plot:
(1,2) in ax = fig.add_subplot(2, 2, (1,2)) does not say location or plot number, isn't it confusing? This is because ax = fig.add_subplot(2, 2, (3,2)) would mean there are 3 plots and taking 2 places but it throws this error
IndexError: GridSpec slice would result in no space allocated for subplot
Why the error?