Oct-16-2018, 05:31 PM
Hi,
I am undertaking an undergraduate in physics and need help plotting measurements for a curve. I am at an absolute novice level in Python.
The curve, itself, is not an issue, per say... It's the curve fitting I'm interested in.
My code is not beautiful, I know:
It outputs:
![[Image: 93a24f574765927117a7f545d4c26d53.png]](https://i.gyazo.com/93a24f574765927117a7f545d4c26d53.png)
It might jag be me who's picky but I would very much like a smooth curve to fit my measurements.
The date for the rapport is due tomorrow, so help would be VERY apprecieated!
PS. I do not have time for any "deeper" lectures in Python at this moment, I really need someone to hold my hand while I'm doing this so I can focus on my actual lectures which for this lab is electro magnetism...
Thanks a lot in advance!
I am undertaking an undergraduate in physics and need help plotting measurements for a curve. I am at an absolute novice level in Python.
The curve, itself, is not an issue, per say... It's the curve fitting I'm interested in.
My code is not beautiful, I know:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import matplotlib.pyplot as plt ydata = [ 34 , 33.3 , 32.6 , 31.8 , 30.9 , 29.9 , 28.9 , 27.9 , 26.9 , 26 , 25.1 , 24.3 , 23.6 , 22.8 , 22.4 , 21.9 , 21.7 , 21.6 , 21.6 , 21.8 , 22 , 22.4 , 22.9 , 23.5 , 24.2 , 24.9 , 25.6 , 26.4 , 27.2 , 28 , 28.7 , 29.4 , 30 , 30.6 , 31.1 , 31.5 , 31.7 , 31.9 , 31.9 , 31.8 , 31.7 , 31.4 , 31.1 , 30.7 , 30.2 , 29.7 , 29 , 28.4 , 27.8 , 27.2 , 26.1 , 26 , 25.5 , 25 , 24.6 , 24.3 , 24.1 , 23.9 , 23.8 , 23.8 , 23.9 , 24.1 , 24.3 , 24.6 , 25 , 25.4 , 25.8 , 26.3 , 26.8 , 27.3 , 27.7 , 28.2 , 28.7 , 29 , 29.4 , 29.7 , 29.9 , 30 , 30.1 , 30.2 , 30.1 , 30 , 29.8 , 29.7 , 29.5 , 29.3 , 28.9 , 28.6 , 28.2 , 27.8 , 27.4 , 27 , 26.7 , 26.3 , 26 , 25.7 , 25.5 , 25.3 , 25.2 , 25.2 , 25.2 , 25.2 , 25.3 , 25.5 , 25.6 , 25.9 , 26.1 , 26.4 , 26.7 , 27 , 27.3 , 27.6 , 27.9 , 28.2 , 28.4 , 28.7 , 28.9 , 29 , 29.2 , 29.2 , 29.2 , 29.2 , 29.2 , 29.1 , 28.9 , 28.8 , 28.6 , 28.4 , 28.2 , 28 , 27.7 , 27.5 , 27.3 , 27 , 26.8 , 26.6 , 26.5 , 26.4 , 26.3 , 26.2 , 26.2 , 26.2 , 26.2 , 26.3 , 26.4 , 26.4 , 26.6 , 26.7 , 26.9 , 27.1 , 27.2 , 27.4 , 27.6 , 27.8 , 28 , 28.1 , 28.2 , 28.3 , 28.4 , 28.5 , 28.5 , 28.6 , 28.6 , 28.5 , 28.3 , 28.3 , 28.2 , 28.1 , 28 , 27.8 , 27.7 , 27.5 , 27.4 , 27.2 , 27.1 , 26.9 , 26.8 , 26.7 , 26.7 , 26.6 ] xdata = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 ] plt.scatter(xdata, ydata) cur_axes = plt.gca() cur_axes.axes.get_xaxis().set_visible( False ) plt.title("") xerr = 0 yerr = 0 plt.savefig( "m1.pdf" ) plt.show() |
![[Image: 93a24f574765927117a7f545d4c26d53.png]](https://i.gyazo.com/93a24f574765927117a7f545d4c26d53.png)
It might jag be me who's picky but I would very much like a smooth curve to fit my measurements.
The date for the rapport is due tomorrow, so help would be VERY apprecieated!
PS. I do not have time for any "deeper" lectures in Python at this moment, I really need someone to hold my hand while I'm doing this so I can focus on my actual lectures which for this lab is electro magnetism...
Thanks a lot in advance!