<jupyter_start><jupyter_text>Making Multipanel Plots with Mathplotlib first we import numpy and matplotlib as usual<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100)
print(x[-1], 2*np.pi)

y = np.sin(x)
z = np.cos(x)
w = np.sin(4*x)
v = np.cos(4*x)<jupyter_output><empty_output><jupyter_text>Now lets make a 2 panel plot side-by-side<jupyter_code>#call subplots to generate a multipanel figure. This means one row, 2 columns of figures.
f, axarr = plt.subplots(1, 2)

#treat axarr as an array from left to right

#first panel
axarr[0].plot(x, y)
axarr[0].set_ylabel('sin(x)')
axarr[0].set_xlabel('x')
axarr[0].set_title(r'$\sin(x)$')

#second panel
axarr[1].plot(x,z)
axarr[1].set_ylabel('cos(x)')
axarr[1].set_xlabel('x')
axarr[1].set_title(r'$\cos(x)$')<jupyter_output><empty_output><jupyter_text>Here we can see that matplotlib has the panels too close together.  We can adjust that using the subplots_adjust() function<jupyter_code>#call subplots to generate a multipanel figure. This means one row, 2 columns of figures.
f, axarr = plt.subplots(1, 2)

#treat axarr as an array from left to right

#first panel
axarr[0].plot(x, y)
axarr[0].set_ylabel('sin(x)')
axarr[0].set_xlabel('x')
axarr[0].set_title(r'$\sin(x)$')

#second panel
axarr[1].plot(x,z)
axarr[1].set_ylabel('cos(x)')
axarr[1].set_xlabel('x')
axarr[1].set_title(r'$\cos(x)$')\

#add more space between the figures
f.subplots_adjust(wspace =0.6)<jupyter_output><empty_output><jupyter_text>OK, but the axis ratios are all squished. Let's fix that too.<jupyter_code>#call subplots to generate a multipanel figure. This means one row, 2 columns of figures.
f, axarr = plt.subplots(1, 2)

#treat axarr as an array from left to right

#first panel
axarr[0].plot(x, y)
axarr[0].set_ylabel('sin(x)')
axarr[0].set_xlabel('x')
axarr[0].set_title(r'$\sin(x)$')

#second panel
axarr[1].plot(x,z)
axarr[1].set_ylabel('cos(x)')
axarr[1].set_xlabel('x')
axarr[1].set_title(r'$\cos(x)$')\

#add more space between the figures
f.subplots_adjust(wspace =0.6)

#fix the axis ratios
#there are two possible options
axarr[0].set_aspect('equal')    #make the ratio of the tick units equal
axarr[1].set_aspect(np.pi)      #make a square by setting the aspect to be the ratio of the tick unit range<jupyter_output><empty_output><jupyter_text>Alright, let's keep the square figure,merge them into one, remove the titles, and add legends.<jupyter_code>#Adjust the size of the figure
fig =plt.figure(figsize=(6,6))

plt.plot(x, y, label=r'$y = \sin(x)$')    #add a label to the line
plt.plot(x, z, label=r'$y = \cos(x)$')    #add a label to the second line
plt.plot(x, w, label=r'$y = \sin(4x)$')   #etc.
plt.plot(x, v, label=r'$y = \cos(4x)$')

plt.xlabel(r'$x$')                        #Note set_xlabel vs. xlabel
plt.ylabel(r'$y(x)$')                     #Note set_ylabel vs. ylabel
plt.xlim([0, 2*np.pi])                    #Note set_xlim vs. xlim
plt.ylim([-1.2, 1.2])                     #Note set_ylim vs. ylim
plt.legend(loc=1, framealpha=0.95)        #add a legend with a semi-transparent frame in the upper RH corner

#fix the axis ratio
plt.gca().set_aspect(np.pi/1.2)           #use "gca" to get current axis()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15368098159509203, 'fraction_numerical': 0.019938650306748466, 'mean_word_length': 4.632124352331606, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '166363', 'license': 'MIT', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1286, 'n_words': 342, 'path': 'Test_Multipanel.ipynb', 'repo_name': 'tiseever/ASTR-119-Lecture-7', 'size': '3260'}