Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 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. "%matplotlib inline\n",
  22. "\n",
  23. "#Create arrays for your data\n",
  24. "\n",
  25. "theta_array = np.array([37.5,40.5,43.5,46.5,49.5])\n",
  26. "ymean_array = np.array([86.7,90.98,94.22,90.2,85.8])\n",
  27. "\n",
  28. "\n",
  29. "#Create and array for your y-axis uncertainties\n",
  30. "\n",
  31. "yerr_array = np.array([.05,.05,.05,.05,.05])\n",
  32. "\n",
  33. "#Reassign variables\n",
  34. "x = theta_array\n",
  35. "y = ymean_array\n",
  36. "dy = yerr_array\n",
  37. "\n",
  38. "#size the plot\n",
  39. "plt.figure(figsize=(15,10))\n",
  40. "\n",
  41. "#create scatter plot\n",
  42. "plt.scatter(x, y, color='blue', marker='o')\n",
  43. "\n",
  44. "#create labels\n",
  45. "plt.xlabel('$\\\\theta$ (degrees)')\n",
  46. "plt.ylabel('$y_{mean}$ (m)')\n",
  47. "plt.title('Height on wall vs Launcher Angle')\n",
  48. "\n",
  49. "#fitting to a 2nd degree polynomial\n",
  50. "c,b,a=np.polynomial.polynomial.polyfit(x,y,2,w=dy)\n",
  51. "\n",
  52. "#Annotate with values of A, B, C from best fit polynomial\n",
  53. "plt.annotate('A = {value:.{digits}E}'.format(value=a, digits=3),\n",
  54. " (0.05, 0.9), xycoords='axes fraction')\n",
  55. "\n",
  56. "plt.annotate('B = {value:.{digits}E}'.format(value=b, digits=3),\n",
  57. " (0.05, 0.85), xycoords='axes fraction')\n",
  58. " \n",
  59. "plt.annotate('C = {value:.{digits}E}'.format(value=c, digits=3),\n",
  60. " (0.05, 0.8), xycoords='axes fraction')\n",
  61. "#Create fit line\n",
  62. "xnew = np.linspace(x.min(), x.max(), 300)\n",
  63. "fit = a*xnew**2 + b*xnew +c\n",
  64. "\n",
  65. "plt.scatter(xnew, fit, color='red')\n",
  66. "plt.show()\n",
  67. "\n",
  68. "print \"C = \",c , \"B = \",b, \"A = \",a\n"
  69. ]
  70. }
  71. ],
  72. "metadata": {
  73. "kernelspec": {
  74. "display_name": "Python 2",
  75. "language": "python",
  76. "name": "python2"
  77. },
  78. "language_info": {
  79. "codemirror_mode": {
  80. "name": "ipython",
  81. "version": 2
  82. },
  83. "file_extension": ".py",
  84. "mimetype": "text/x-python",
  85. "name": "python",
  86. "nbconvert_exporter": "python",
  87. "pygments_lexer": "ipython2",
  88. "version": "2.7.11"
  89. }
  90. },
  91. "nbformat": 4,
  92. "nbformat_minor": 0
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement