Lab 2: Plotting and Visualization - ChrisPerez13/CompPhys GitHub Wiki
Goal
The goal of this lab was to learn how to plot complex functions and how to visualize them since we will be doing this throughout the semester. We downloaded data sets and modified them into arrays to be plotted showing their relationships. We downloaded images and created lines of best fit for a data set. Used standard deviation and mean lines on a histogram to show values.
Overview
Download Data Set
Use the !wget to download data sets and use np.loadtxt to read the data
!wget
star_data = np.loadtxt('stars.txt')
Plot Sine and Cosine Functions
theta = np.linspace(0,2*np.pi,200)
r = np.sin(theta)
Downloading Images
!wget
myimage = image.imread("_____")
plt.imshow(myimage)
Fitting a Straight Line to Data
c = np.polyfit(x,y,1)
xline = np.linspace(xmin,xmax,100)
yline = np.polyval(c,xline)
Histogram of Random Numbers Showing Mean and Standard Deviation
gauss_values = np.random.normal(size=100)
plt.hist(gauss_values)
print("average value = {:.2f}".format(np.mean(gauss_values)))
print("the STD = {:.2f}".format(np.std(gauss_values)))
plt.axvline(np.mean(gauss_values),color='red')
plt.axvline(np.std(gauss_values),color='blue',linestyle='--')
plt.axvline(-np.std(gauss_values),color='cyan',linestyle='--')