I have a dataframe with 4 columns and I want to plot each two columns in combination as line plots. The columns are independent of each other. But I want to plot them pairwise. This would eventually give me an n*n grid of subplots, which looks like this 4x4 gridplot using matplotlib subplot
This was generated using the following code. Since I can not upload the original df, I have created a fake one here.
Number_1 = np.random.uniform(0.5, 0, 30)
Number_2 = np.random.uniform(0.5, 0.25, 30)
Number_3 = np.random.uniform(-0.25, 0.25, 30)
Number_4 = np.random.uniform(0.25, 0, 30)
columns = ['Number_1','Number_2','Number_3','Number_4']
loadings = pd.DataFrame([Number_1,Number_2,Number_3,Number_4]).T
loadings.columns = columns
fig, axs = plt.subplots(loadings.shape[1], loadings.shape[1],figsize=(20,12),tight_layout=True)
fig.suptitle('Loading diagram for each component', fontsize=25)
for i in range(axs.shape[0]):
for j in range(axs.shape[1]):
if i!=j:
axs[i,j].plot(loadings[columns[i]],label=columns[i])
axs[i,j].plot(loadings[columns[j]],label=columns[j])
axs[i,j].legend()
axs[i,j].set_xlabel('x axis title')
else:
axs[i,j].axis('off')
plt.show()
But what I could not figure out was how I could add an outer common axis title for each row and column of the grid. What I want would eventually look like this desired result. Notice the Number_1, Number_2 etc. titles on the outer axes.
One thing that I found on matplotlib was using subfigures. But I could not figure out (pun intended) how to create both horizontal and vertical figures and then name them. I would really appreciate the help. Thank you very much!