Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm studying and playing around with a piece of code and Im confused as to what the line plt.subplot(121) means. I've tried changing the 121 and it seems to make the graph wider or narrower or disappear altogether. It's used again but with 122 instead. Could anyone help me out with its meaning/function?

What I have tried:

from scipy.stats import linregress
import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt('EP305_lecture_11_data1.dat')

xcol, ycol = 0, 1
x, y = data[:,xcol], data[:,ycol]

S, y0, r, _, sigmaS = linregress(x,y)
print(f'Fitted model is y={S:0.3g} x + {y0:.3g}.')
print(f'Uncertainty of the slope is {sigmaS:.3g}.')

plt.subplot(121)
plt.xlabel('x [l]')
plt.ylabel('y [l]')
plt.plot(x,y,'kx')
plt.plot(x,S * x + y0)
plt.subplot(122)
plt.xlabel('x [l]')
plt.ylabel('residuals [l]')
plt.plot(x,y-(S * x + y0),'k')
plt.tight_layout()
Posted
Updated 4-May-20 2:57am

1 solution

 
Share this answer
 
Comments
MadMyche 4-May-20 9:06am    
+5 for the valid RTFM response
phil.o 4-May-20 9:12am    
I'd prefer KRTTD: Kindly refer to the documentation.
Thanks :)
Richard MacCutchan 4-May-20 9:30am    
Nothing wrong with "Read This Fine Manual".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900