<jupyter_start><jupyter_text>Matplotlib><jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
plt.style.available
plt.style.use('seaborn')
xs = np.linspace(0, 2*np.pi, 400)
ys = np.sin(xs**2)

xc = np.linspace(0, 2*np.pi, 600)
yc = np.cos(xc**2)
# Usual way to create plot
fig, ax = plt.subplots(2, 2, figsize=(16,8))
ax[0,0].plot(xs, ys)
ax[1,1].plot(xs, ys)
ax[0,1].plot(xc, yc)
ax[1,0].plot(xc, yc)
fig.suptitle('Basic plotting using matplotlib')
plt.show()<jupyter_output><empty_output><jupyter_text>FigureA `Figure` is your main (imaginary) canvas. This is where plotting/drawing is done. A figure has a size defined for it at the time of creation. **This is the central object with which you will always be interacting.**<jupyter_code># To define a figure
fig = mpl.figure.Figure(figsize=(10,10))

# OR
fig = plt.figure(figsize=(10,10))<jupyter_output><empty_output><jupyter_text>AxesA Figure by itself does not have any place to plot. You need to attach/add `Axes` to it to do any kind of plotting. You can put as many Axes objects as you want inside of any Figure you have created.An Axes has:1. Space (like a blank page) where you can plot.2. Parent `Figure`.3. Propoerties stating where it will be placed inside it's parent `Figure`.4. Methods to draw/plot different kinds of data.<jupyter_code># To create an axis
ax1 = mpl.axes.Axes(fig=fig, rect=[0, 0, 0.8, 0.8], facecolor='red')

# OR
ax1 = plt.Axes(fig=fig, rect=[0, 0, 0.8, 0.8], facecolor='red') #[left_position, bottom_position, height, width] represented as percentages
ax1<jupyter_output><empty_output><jupyter_text>plt.subplots reference example<jupyter_code>fig, ax = plt.subplots(2,2)
fig.suptitle("2x2 Grid")<jupyter_output><empty_output><jupyter_text>Using matplotlib's primitves<jupyter_code># Create figure (canvas)
fig = plt.figure(figsize=(6,6))

# Create Axes (notes these are not yet connected to fig)
ax1 = plt.Axes(fig=fig, rect=[0.3, 0.3, 0.4, 0.4], facecolor='red')
ax2 = plt.Axes(fig=fig, rect=[0, 0, 1, 1], facecolor='blue')
# Add Axes to the Figure
fig.add_axes(ax2)
fig.add_axes(ax1)
fig
# Axes can also be removed
fig.delaxes(ax1)
fig
mpl.__version__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13729043951064793, 'fraction_numerical': 0.03398278205709107, 'mean_word_length': 5.711246200607903, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '141571', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 846, 'n_words': 246, 'path': 'libs/matplotlib.ipynb', 'repo_name': 'KushajveerSingh/pytorch_projects', 'size': '2207'}