Skip to content

Graphing and Analyzing Data

Hannah Si edited this page Oct 4, 2018 · 1 revision

This page is under construction.

Graphing from Manually Entered Points

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

# Replace coordinates here with your data. Make as many coordinates as necessary.
data_points = np.array([[1,3],
                       [2,5],
                       [3,7],
                       [4,8],
                       [5,11],
                       [6,14]])

x_points = data_points[:,0]
y_points = data_points[:,1]
# You can modify the above 2 lines to ]perform operations on your data here such as
#y_points = np.log10(data_points[:,1])

linreg = stats.linregress(x_points, y_points)
slope, intercept, r_value = linreg[0:3]

start = 0 # Change as desired
end = x_points[-1] # last element; change as desired
plt.plot(x_points, y_points, 'o', color="blue")
plt.plot(np.arange(start,end+1), np.arange(start,end+1)*slope + intercept)
plt.xlabel('X Label')
plt.ylabel('Y label')
plt.title('Title')
plt.minorticks_on()
plt.grid(which = 'major')
plt.show()

Graphing from Spreadsheet

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import pandas as pd

data = pd.read_csv('example_data.csv')

#get x_points and y_points
x_column_index = 0
x_points = data.iloc[:, x_column_index]
y_column_index = 1
y_points = data.iloc[:, y_column_index]

#calculate linear regression statistics
linreg = stats.linregress(x_points, y_points)
slope, intercept, r_value = linreg[0:3]

start = 0 # Change as desired
end = x_points[x_points.size-1]
plt.plot(x_points, y_points, 'o', color="blue")
plt.plot(np.arange(start,end+1), np.arange(start,end+1)*slope + intercept)
plt.xlabel('X Label')
plt.ylabel('Y label')
plt.title('Title')
plt.minorticks_on()
plt.grid(which = 'major')
plt.show()

print("Slope:", slope)
print("Intercept:", intercept)
print("R-squared:", r_value ** 2)

Graphing from ProCoDA Data

Clone this wiki locally