<jupyter_start><jupyter_text>Matplotlib Sub Plots<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(0, 10, 11)
b = a**4
x = np.arange(0, 10)
y = x * 2<jupyter_output><empty_output><jupyter_text>Adding rows and columns<jupyter_code>fig, axes = plt.subplots(nrows=1, ncols=2)

axes[0].plot(x, y)
axes[1].plot(a, b)
axes.shape
axes<jupyter_output><empty_output><jupyter_text>------<jupyter_code>fig, axes = plt.subplots(nrows=2, ncols=2)

axes[0][0].plot(x, y)
axes[1][1].plot(a, b)
axes.shape
axes<jupyter_output><empty_output><jupyter_text>------  Loop through axes<jupyter_code>fig, axes = plt.subplots(nrows=3, ncols=1)

for ax in axes:
    ax.plot(x, y)<jupyter_output><empty_output><jupyter_text>------  fixing overlapping area betweens figures- plt.tight_layout()- fig.tight_layout()<jupyter_code>fig, axes = plt.subplots(nrows=3, ncols=1)

for ax in axes:
    ax.plot(x, y)

plt.tight_layout()<jupyter_output><empty_output><jupyter_text>------  Manually set spacing between figures* left = 0.125   the left side of the subplots of the figure* right = 0.9    the right side of the subplots of the figure* bottom = 0.1   the bottom of the subplots of the figure* top = 0.9      the top of the subplots of the figure* wspace = 0.2   the amount of width reserved for space between subplots,               expressed as a fraction of the average axis width* hspace = 0.2   the amount of height reserved for space between subplots,               expressed as a fraction of the average axis height<jupyter_code>fig, axes = plt.subplots(nrows=2, ncols=2)

axes[0][0].plot(x,y)
axes[0][1].plot(a,b)
axes[1][0].plot(x,y)
axes[1][1].plot(a,b)

# manully set the spacing
fig.subplots_adjust(left=None,
    bottom=None,
    right=None,
    top=None,
    wspace=0.9,
    hspace=0.3,)

plt.show()<jupyter_output><empty_output><jupyter_text>-------------  Parameters on subplots()<jupyter_code>fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12,8), dpi=100)

axes[0][0].plot(x,y)
axes[0][0].set_title('0 0 Title')

axes[0][1].plot(a,b)
axes[0][1].set_ylabel('ylabel 0,1')
axes[0][1].set_xlim(1, 8)

axes[1][0].plot(x,y)

axes[1][1].plot(a,b)
axes[1][1].set_title('Title 1,1')

# super title
fig.suptitle('Whole Figure Title', fontsize=16)

plt.tight_layout()
plt.show()

fig.savefig('Figures/new_subplots.png', bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16240033571128829, 'fraction_numerical': 0.0360889634913974, 'mean_word_length': 4.88641975308642, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '566343', 'license': 'MIT', 'n_tokens_mistral': 1036, 'n_tokens_neox': 958, 'n_words': 208, 'path': 'Machine Learning & Data Science Masterclass - JP/04-Matplotlib/02-Matplotlib-SubPlots.ipynb', 'repo_name': 'ptyadana/probability-and-statistics-for-business-and-data-science', 'size': '2383'}