Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import numpy as np\n",
  12. "import matplotlib.pyplot as plt\n",
  13. "\n",
  14. "#--------------------------#\n",
  15. "#When you make your iPython notebook,\n",
  16. "#add the following line at the top of your code\n",
  17. "#after your comments:\n",
  18. "# %matplotlib inline\n",
  19. "#--------------------------#\n",
  20. "\n",
  21. "#Create arrays for your data\n",
  22. "\n",
  23. "\n",
  24. "#Create and array for your y-axis uncertainties\n",
  25. "\n",
  26. "\n",
  27. "#Reassign variables\n",
  28. "x = np.array([42,39,36,45,48])\n",
  29. "y = np.array([0.806,0.774,0.7075,0.7515,0.691])\n",
  30. "dy = np.array([0.0062,0.00868,0.00504,0.0111,0.005184])\n",
  31. "\n",
  32. "#size the plot\n",
  33. "plt.figure(figsize=(15,10))\n",
  34. "\n",
  35. "#create scatter plot\n",
  36. "plt.scatter(x, y, color='blue', marker='o')\n",
  37. "\n",
  38. "#create labels\n",
  39. "plt.xlabel('$\\\\theta$ (degrees)')\n",
  40. "plt.ylabel('$y_{mean}$ (m)')\n",
  41. "plt.title('Height on wall vs Launcher Angle')\n",
  42. "\n",
  43. "#fitting to a 2nd degree polynomial\n",
  44. "c,b,a=np.polynomial.polynomial.polyfit(x,y,2,w=dy)\n",
  45. "\n",
  46. "#Annotate with values of A, B, C from best fit polynomial\n",
  47. "plt.annotate('A = {value:.{digits}E}'.format(value=a, digits=3),\n",
  48. " (0.05, 0.9), xycoords='axes fraction')\n",
  49. "\n",
  50. "plt.annotate('B = {value:.{digits}E}'.format(value=b, digits=3),\n",
  51. " (0.05, 0.85), xycoords='axes fraction')\n",
  52. " \n",
  53. "plt.annotate('C = {value:.{digits}E}'.format(value=c, digits=3),\n",
  54. " (0.05, 0.8), xycoords='axes fraction')\n",
  55. "#Create fit line\n",
  56. "xnew = np.linspace(x.min(), x.max(), 300)\n",
  57. "fit = a*xnew**2 + b*xnew +c\n",
  58. "\n",
  59. "plt.scatter(xnew, fit, color='red')\n",
  60. "plt.show()\n",
  61. "\n",
  62. "print \"C = \",c , \"B = \",b, \"A = \",a"
  63. ]
  64. }
  65. ],
  66. "metadata": {
  67. "kernelspec": {
  68. "display_name": "Python 2",
  69. "language": "python",
  70. "name": "python2"
  71. },
  72. "language_info": {
  73. "codemirror_mode": {
  74. "name": "ipython",
  75. "version": 2
  76. },
  77. "file_extension": ".py",
  78. "mimetype": "text/x-python",
  79. "name": "python",
  80. "nbconvert_exporter": "python",
  81. "pygments_lexer": "ipython2",
  82. "version": "2.7.11"
  83. }
  84. },
  85. "nbformat": 4,
  86. "nbformat_minor": 0
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement