Skip to content

Instantly share code, notes, and snippets.

@taiypeo
Created February 25, 2018 12:36
Show Gist options
  • Save taiypeo/59565a9e6510e7d833b73e9cd6f88236 to your computer and use it in GitHub Desktop.
Save taiypeo/59565a9e6510e7d833b73e9cd6f88236 to your computer and use it in GitHub Desktop.
A simple graphing program on Python for my experimental physics classes
import matplotlib.pyplot as plt
def get_input():
print('X label?')
xlabel = input()
print('Y label?')
ylabel = input()
print('dx?')
xerr = float(input())
print('dy?')
yerr = float(input())
print('How many experimental points?')
points_num = int(input())
print('Enter your points')
x = []
y = []
for i in range(points_num):
xy = input().split()
x.append(float(xy[0]))
y.append(float(xy[1]))
return xlabel, ylabel, x, y, xerr, yerr
def main():
xlabel, ylabel, x, y, xerr, yerr = get_input()
plt.rc('grid', linestyle='--', color='black')
plt.grid()
plt.errorbar(x, y, xerr=xerr, yerr=yerr, capsize=3, fmt='o')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment