Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import matplotlib.pyplot as plt\n",
- "\n",
- "#--------------------------#\n",
- "#When you make your iPython notebook,\n",
- "#add the following line at the top of your code\n",
- "#after your comments:\n",
- "# %matplotlib inline\n",
- "#--------------------------#\n",
- "\n",
- "#Create arrays for your data\n",
- "\n",
- "\n",
- "#Create and array for your y-axis uncertainties\n",
- "\n",
- "\n",
- "#Reassign variables\n",
- "x = np.array([42,39,36,45,48])\n",
- "y = np.array([0.806,0.774,0.7075,0.7515,0.691])\n",
- "dy = np.array([0.0062,0.00868,0.00504,0.0111,0.005184])\n",
- "\n",
- "#size the plot\n",
- "plt.figure(figsize=(15,10))\n",
- "\n",
- "#create scatter plot\n",
- "plt.scatter(x, y, color='blue', marker='o')\n",
- "\n",
- "#create labels\n",
- "plt.xlabel('$\\\\theta$ (degrees)')\n",
- "plt.ylabel('$y_{mean}$ (m)')\n",
- "plt.title('Height on wall vs Launcher Angle')\n",
- "\n",
- "#fitting to a 2nd degree polynomial\n",
- "c,b,a=np.polynomial.polynomial.polyfit(x,y,2,w=dy)\n",
- "\n",
- "#Annotate with values of A, B, C from best fit polynomial\n",
- "plt.annotate('A = {value:.{digits}E}'.format(value=a, digits=3),\n",
- " (0.05, 0.9), xycoords='axes fraction')\n",
- "\n",
- "plt.annotate('B = {value:.{digits}E}'.format(value=b, digits=3),\n",
- " (0.05, 0.85), xycoords='axes fraction')\n",
- " \n",
- "plt.annotate('C = {value:.{digits}E}'.format(value=c, digits=3),\n",
- " (0.05, 0.8), xycoords='axes fraction')\n",
- "#Create fit line\n",
- "xnew = np.linspace(x.min(), x.max(), 300)\n",
- "fit = a*xnew**2 + b*xnew +c\n",
- "\n",
- "plt.scatter(xnew, fit, color='red')\n",
- "plt.show()\n",
- "\n",
- "print \"C = \",c , \"B = \",b, \"A = \",a"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 2",
- "language": "python",
- "name": "python2"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.11"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement