Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# SPDX-FileCopyrightText: 2020 Jonathan Pieper <jpieper@stud.uni-frankfurt.de> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5# -*- coding: utf-8 -*- 

6""" 

7Main plotting class to handle plots. 

8""" 

9 

10import matplotlib.pyplot as plt 

11from mpl_toolkits.axes_grid1.inset_locator import inset_axes 

12import seaborn as sns 

13import numpy as np 

14 

15# Math / Science Libraries 

16import scipy 

17 

18from .handle import HandleM 

19from .hloop import Hloop 

20from .plotting import PlottingClass 

21 

22 

23class Plot(object): 

24 def __init__(self): 

25 """A small class used to plot figures for a presentation.""" 

26 

27 super().__init__() 

28 

29 self.meas = {} 

30 self.m = Hloop(57) 

31 self.eva = HandleM(directory='data/SR785') 

32 

33 def get_plot(self, **kwargs): 

34 fig, ax = plt.subplots(nrows=kwargs.get('nrows', 1), 

35 ncols=kwargs.get('ncols', 1), 

36 figsize=kwargs.get('figsize', (16, 12)) 

37 ) 

38 return fig, ax 

39 

40 def set_plot_style(self, m=None, **kwargs): 

41 if m is None: 

42 m = self.m 

43 

44 m.style.set_style(size=kwargs.get('size', 'talk'), 

45 style=kwargs.get('style', 'ticks'), 

46 palette=kwargs.get('palette', 'deep'), 

47 grid=kwargs.get('grid', True), 

48 latex=kwargs.get('latex', True), 

49 figsize=kwargs.get('figsize', (16, 12)) 

50 ) 

51 

52 def plot_single_hloop(self, nr=54, filename='hloop-single-1', 

53 **kwargs): 

54 """Plots a single measurement. Default: 0deg 

55 

56 Args: 

57 nr: 

58 filename (str, optional): File to write. The default is 

59 'hloop-single-1'. 

60 xlim / ylim: limit the plots axes. 

61 

62 Returns: 

63 {filename}.pdf 

64 """ 

65 fig, ax = self.get_plot(**kwargs) 

66 

67 if nr not in self.meas: 

68 self.meas[nr] = Hloop(nr) 

69 

70 self.set_plot_style(self.meas[nr]) 

71 self.meas[nr].plot_strayfield(ax) 

72 ax.set_xlim(*kwargs.get('xlim', (-250, 250))) 

73 if kwargs.get('ylim'): 

74 ax.set_ylim(*kwargs.get('ylim')) 

75 

76 with sns.color_palette('deep'): 

77 self.set_plot_style(self.m) 

78 inset = inset_axes(ax, width='100%', height='90%', 

79 bbox_to_anchor=(.64, .06, .35, .35), 

80 bbox_transform=ax.transAxes) 

81 max_b = self.meas[nr].up.B.max() 

82 inset.plot([-max_b, max_b], [0, 0], 'r--', linewidth=.75) 

83 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

84 inset.plot(B_ext, B_stray) 

85 inset.set_ylabel("$\\Delta B_z\\;[\\mathrm{mT}]$") 

86 inset.set_title("Difference") 

87 inset.set_xlim(*kwargs.get('xlim', (-250, 250))) 

88 

89 plt.savefig("%s.pdf" % filename) 

90 

91 def plot_hloops(self, to_show=[54, 55], filename='hloop-compare-1', 

92 **kwargs): 

93 """Compares Plusses and Crosses between two angles (4 Subplots). 

94 Default: 0 and 45 Writes file hloop-compare-1.pdf 

95 

96 Args: 

97 to_show (list, optional): List of 4 measurement numbers,  

98 defaults to [54, 55] 

99 filename (str, optional): DESCRIPTION, defaults to 'hloop-compare-1' 

100 **kwargs: 

101 

102 Returns: 

103 None 

104 """ 

105 self.m.style.set_style(default=True, grid=True, 

106 size='talk', style='ticks', 

107 palette='deep', latex=True) 

108 fig, axes = self.get_plot(nrows=2, ncols=2) 

109 

110 for i, nr in enumerate(to_show): 

111 ax = axes[i // 2][i % 2] 

112 if nr not in self.meas: 

113 self.meas[nr] = Hloop(nr) 

114 

115 self.set_plot_style(self.meas[nr]) 

116 self.meas[nr].plot_strayfield(ax) 

117 ax.set_xlim(-250, 250) 

118 if nr in [54]: 

119 ax.set_ylim(0, 4.5) 

120 if nr in [55]: 

121 ax.set_xlim(-300, 300) 

122 ax.set_ylim(-0.8, 4.45) 

123 if nr in [22, 23]: 

124 ax.set_xlim(-150, 150) 

125 if kwargs.get('xlim'): 

126 ax.set_xlim(*kwargs.get('xlim')) 

127 

128 with sns.color_palette('deep'): 

129 self.set_plot_style(self.m) 

130 inset = inset_axes(ax, width='100%', height='90%', 

131 bbox_to_anchor=(.65, .09, .35, .35), 

132 bbox_transform=ax.transAxes) 

133 max_b = self.meas[nr].up.B.max() 

134 inset.plot([-max_b, max_b], [0, 0], 'r--', linewidth=.75) 

135 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

136 inset.plot(B_ext, B_stray) 

137 inset.set_ylabel("$\\Delta B_z\\;[\\mathrm{mT}]$") 

138 inset.set_title("Difference") 

139 inset.set_xlim(-250, 250) 

140 if nr in [55]: 

141 inset.set_xlim(-300, 300) 

142 if nr in [22, 23]: 

143 inset.set_xlim(-150, 150) 

144 if kwargs.get('xlim'): 

145 inset.set_xlim(*kwargs.get('xlim')) 

146 inset.set_yticks(kwargs.get('diff_yticks', [0, 0.5, 1])) 

147 

148 plt.savefig("%s.pdf" % filename) 

149 

150 def plot_hloops_95(self, 

151 to_show=[42, 43, 32, 34], 

152 filename='hloop-compare-95', 

153 **kwargs): 

154 """Compares +95/100/105/110deg with -85/80/75/70deg for (180deg 

155 Comparison) 

156 

157 :param filename:Filename to save. The default is 'hloop-compare-95'. 

158 :type filename: str, optional 

159 

160 Args: 

161 to_show (list, optional): Measurement numbers to plot. The default 

162 is a[95]+a[-85]. 

163 filename: 

164 **kwargs: 

165 

166 Returns: 

167 {filename}.pdf 

168 """ 

169 fig, axes = plt.subplots(2, 2, figsize=(16, 12)) 

170 for i, nr in enumerate(to_show): 

171 ax = axes[i // 2][i % 2] 

172 if nr not in self.meas: 

173 self.meas[nr] = Hloop(nr) 

174 self.set_plot_style(self.meas[nr]) 

175 self.meas[nr].plot_strayfield(ax) 

176 if kwargs.get('xlim'): 

177 ax.set_xlim(*kwargs.get('xlim')) 

178 else: 

179 ax.set_xlim(-750, 750) 

180 if self.meas[nr].info['Structure'] == 'Crosses' and kwargs.get( 

181 'crosses_xlim'): 

182 ax.set_xlim(*kwargs.get('crosses_xlim')) 

183 

184 with sns.color_palette('deep'): 

185 self.m.style.set_style(size='talk', style='ticks', 

186 grid=True, latex=True) 

187 inset = inset_axes(ax, width='100%', height='90%', 

188 bbox_to_anchor=(.65, .09, .35, .35), 

189 bbox_transform=ax.transAxes) 

190 max_b = self.meas[nr].up.B.max() 

191 inset.plot([-max_b, max_b], [0, 0], 'r--', linewidth=.75) 

192 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

193 inset.plot(B_ext, B_stray) 

194 # inset.set_ylabel("$\Delta B_z\\;[\\mathrm{mT}]$") 

195 inset.set_title("Difference") 

196 if kwargs.get('xlim'): 

197 inset.set_xlim(*kwargs.get('xlim')) 

198 else: 

199 inset.set_xlim(-750, 750) 

200 if self.meas[nr].info['Structure'] == 'Crosses' and kwargs.get( 

201 'crosses_xlim'): 

202 inset.set_xlim(*kwargs.get('crosses_xlim')) 

203 

204 plt.savefig("%s.pdf" % filename) 

205 

206 def plot_hloops_90(self, 

207 to_show=[57, 155], 

208 filename='hloop-compare-90', 

209 **kwargs): 

210 """Compares +90deg with -90deg for (180deg Comparison) 

211 

212 Args: 

213 to_show (TYPE, optional): DESCRIPTION. The default is [57,155]. 

214 filename (TYPE, optional): DESCRIPTION. The default is 

215 'hloop-compare-90'. 

216 **kwargs (TYPE): mirror: bool, optional 

217 should we mirror the hloop? The default is False 

218 

219 Returns: 

220 None.: 

221 """ 

222 self.m.style.set_style(default=True, grid=True, 

223 size='talk', style='ticks', 

224 palette='deep', latex=True) 

225 sns.set_palette(sns.color_palette("deep")) 

226 

227 fig, axes = plt.subplots(2, 2, figsize=(16, 12)) 

228 for i, nr in enumerate(to_show): 

229 cur_ax = axes[i] 

230 self.m.style.set_style(size='talk', style='ticks', 

231 palette='Paired', 

232 grid=True, latex=True) 

233 

234 self.meas[nr] = Hloop(nr) 

235 self.set_plot_style(self.meas[nr]) 

236 

237 if not (kwargs.get('mirror')) and nr == 57: 

238 self.meas[nr].set_factor(-1) 

239 self.meas[nr].factor = 1 

240 

241 # Plusses 

242 ax = cur_ax[0] 

243 self.meas[nr].plot_strayfield(ax, nolegend=True, 

244 show_plusses=False, 

245 show_crosses=False) 

246 

247 ax.plot(self.meas[nr].up_fitted.B, self.meas[nr].up_fitted.Bx8, 

248 label='Up (fitted)') 

249 ax.plot(self.meas[nr].down_fitted.B, self.meas[nr].down_fitted.Bx8, 

250 label='Down (fitted)') 

251 

252 # Set Limits (x and y Axis) 

253 if kwargs.get('xlim'): 

254 ax.set_xlim(*kwargs.get('xlim')) 

255 else: 

256 ax.set_xlim(-750, 750) 

257 

258 ax.set_ylim(np.min([self.meas[nr].up_fitted.Bx8.min(), 

259 self.meas[nr].down_fitted.Bx8.min()]) - .05, 

260 np.max([self.meas[nr].up_fitted.Bx8.max(), 

261 self.meas[nr].down_fitted.Bx8.max()]) + .05) 

262 

263 if nr == 57: 

264 ax.set_title('M57: Plusses ($90^\circ$)') 

265 else: 

266 ax.set_title('M155: Plusses ($-90^\circ$)') 

267 

268 # Inset with Difference 

269 with sns.color_palette('bright'): 

270 if nr == 57 and not (kwargs.get('mirror')): 

271 bbox = (.11, .59, .34, .35) 

272 else: 

273 bbox = (.11, .12, .34, .35) 

274 inset = inset_axes(ax, width='100%', height='100%', 

275 bbox_to_anchor=bbox, 

276 bbox_transform=ax.transAxes) 

277 max_b = self.meas[nr].up.B.max() 

278 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield( 

279 fitted_data=True) 

280 inset.plot([-max_b, max_b], [0, 0], '--', color='orange', 

281 linewidth=.75) 

282 inset.plot(B_ext, B_stray) 

283 inset.set_xlim(-750, 750) 

284 inset.set_title("Difference (fitted)") 

285 inset.set_yticks(kwargs.get('diff_yticks', [0, 0.5])) 

286 

287 ax.legend(loc='upper right') # , ncol=2) 

288 

289 # Crosses 

290 ax = cur_ax[1] 

291 self.meas[nr].plot_strayfield(ax, nolegend=True, 

292 show_plusses=False, 

293 show_crosses=False) 

294 ax.plot(self.meas[nr].up_fitted.B, 

295 self.meas[nr].up_fitted.Bx9, label='Up (fitted)') 

296 ax.plot(self.meas[nr].down_fitted.B, 

297 self.meas[nr].down_fitted.Bx9, label='Down (fitted)') 

298 

299 # Set Limits (x and y Axis) 

300 if kwargs.get('xlim'): 

301 ax.set_xlim(*kwargs.get('xlim')) 

302 else: 

303 ax.set_xlim(-750, 750) 

304 

305 ax.set_ylim(np.min([self.meas[nr].up_fitted.Bx9.min(), 

306 self.meas[nr].down_fitted.Bx9.min()]) - .05, 

307 np.max([self.meas[nr].up_fitted.Bx9.max(), 

308 self.meas[nr].down_fitted.Bx9.max()]) + .05) 

309 

310 if nr == 57: 

311 ax.set_title('M57: Crosses ($90^\circ$)') 

312 else: 

313 ax.set_title('M155: Crosses ($-90^\circ$)') 

314 

315 # Inset with Difference 

316 with sns.color_palette('bright'): 

317 if nr == 57 and kwargs.get('mirror'): 

318 bbox = (.11, .12, .34, .35) 

319 else: 

320 bbox = (.11, .59, .34, .35) 

321 inset2 = inset_axes(ax, width='100%', height='100%', 

322 bbox_to_anchor=bbox, 

323 bbox_transform=ax.transAxes) 

324 f_up = scipy.interpolate.interp1d(self.meas[nr].up_fitted.B, 

325 self.meas[nr].up_fitted.Bx9) 

326 f_down = scipy.interpolate.interp1d( 

327 self.meas[nr].down_fitted.B, 

328 self.meas[nr].down_fitted.Bx9) 

329 B = np.linspace(self.meas[nr].up.B.min(), 

330 self.meas[nr].up.B.max(), int(1e5)) 

331 downminusup = f_down(B) - f_up(B) 

332 inset2.plot([-max_b, max_b], [0, 0], '--', 

333 color='orange', linewidth=.75) 

334 inset2.plot(B, downminusup, color='green') 

335 inset2.set_xlim(-750, 750) 

336 inset2.set_title("Difference (fitted)") 

337 if nr == 57: 

338 inset.set_yticks([0, .25, 0.5]) 

339 inset2.set_yticks([0, .25, 0.5]) 

340 

341 ax.legend(loc='upper right') # , ncol=2) 

342 

343 plt.savefig("%s.pdf" % filename) 

344 

345 def plot_hloops_90_nofit(self, to_show=[57, 155], 

346 filename='hloop-compare-90', **kwargs): 

347 """Compares +90deg with -90deg for (180deg Comparison) Using not fitted 

348 data 

349 

350 Args: 

351 to_show (TYPE, optional): DESCRIPTION. The default is [57,155]. 

352 filename (TYPE, optional): DESCRIPTION. The default is 

353 'hloop-compare-90'. 

354 **kwargs (TYPE): mirror: bool, optional 

355 should we mirror the hloop? The default is False 

356 

357 Returns: 

358 None.: 

359 """ 

360 self.m.style.set_style(default=True, grid=True, 

361 size='talk', style='ticks', 

362 palette='deep', latex=True) 

363 sns.set_palette(sns.color_palette("deep")) 

364 

365 fig, axes = plt.subplots(2, 2, figsize=(16, 12)) 

366 for i, nr in enumerate(to_show): 

367 cur_ax = axes[i] 

368 self.m.style.set_style(size='talk', style='ticks', 

369 palette='Paired', 

370 grid=True, latex=True) 

371 

372 self.meas[nr] = Hloop(nr) 

373 

374 if not (kwargs.get('mirror')) and nr == 57: 

375 self.meas[nr].set_factor(-1) 

376 self.meas[nr].factor = 1 

377 

378 # Plusses 

379 ax = cur_ax[0] 

380 self.meas[nr].plot_strayfield(ax, nolegend=True, 

381 show_plusses=False, 

382 show_crosses=False) 

383 

384 ax.plot(self.meas[nr].up.B, self.meas[nr].up.Bx8, label='Up') 

385 ax.plot(self.meas[nr].down.B, self.meas[nr].down.Bx8, label='Down') 

386 ax.plot(self.meas[nr].up.B, self.meas[nr].up.Bx13, 

387 label='Up (Empty)') 

388 ax.plot(self.meas[nr].down.B, self.meas[nr].down.Bx13, 

389 label='Down (Empty)') 

390 

391 # Set Limits (x and y Axis) 

392 if kwargs.get('xlim'): 

393 ax.set_xlim(*kwargs.get('xlim')) 

394 else: 

395 ax.set_xlim(-1000, 1000) 

396 

397 ax.set_ylim(np.min([self.meas[nr].up.Bx8.min(), 

398 self.meas[nr].down.Bx8.min()]) - .05, 

399 np.max([self.meas[nr].up.Bx8.max(), 

400 self.meas[nr].down.Bx8.max()]) + .05) 

401 

402 if nr == 57: 

403 ax.set_title('M57: Plusses ($90^\circ$)') 

404 else: 

405 ax.set_title('M155: Plusses ($-90^\circ$)') 

406 

407 # Inset with Difference 

408 with sns.color_palette('bright'): 

409 if nr == 57 and not (kwargs.get('mirror')): 

410 bbox = (.11, .59, .34, .35) 

411 else: 

412 bbox = (.59, .12, .34, .35) 

413 inset = inset_axes(ax, width='100%', height='100%', 

414 bbox_to_anchor=bbox, 

415 bbox_transform=ax.transAxes) 

416 max_b = self.meas[nr].up.B.max() 

417 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

418 inset.plot([-max_b, max_b], [0, 0], '--', color='orange', 

419 linewidth=.75) 

420 inset.plot(B_ext, B_stray) 

421 inset.set_xlim(-1000, 1000) 

422 inset.set_title("Difference") 

423 

424 # Crosses 

425 ax = cur_ax[1] 

426 self.meas[nr].plot_strayfield(ax, nolegend=True, 

427 show_plusses=False, 

428 show_crosses=False) 

429 ax.plot(self.meas[nr].up.B, self.meas[nr].up.Bx9, label='Up') 

430 ax.plot(self.meas[nr].down.B, self.meas[nr].down.Bx9, label='Down') 

431 ax.plot(self.meas[nr].up.B, self.meas[nr].up.Bx13, 

432 label='Up (Empty)') 

433 ax.plot(self.meas[nr].down.B, self.meas[nr].down.Bx13, 

434 label='Down (Empty)') 

435 

436 # Set Limits (x and y Axis) 

437 if kwargs.get('xlim'): 

438 ax.set_xlim(*kwargs.get('xlim')) 

439 else: 

440 ax.set_xlim(-1000, 1000) 

441 

442 ax.set_ylim(np.min([self.meas[nr].up.Bx9.min(), 

443 self.meas[nr].down.Bx9.min()]) - .05, 

444 np.max([self.meas[nr].up.Bx9.max(), 

445 self.meas[nr].down.Bx9.max()]) + .05) 

446 

447 if nr == 57: 

448 ax.set_title('M57: Crosses ($90^\circ$)') 

449 else: 

450 ax.set_title('M155: Crosses ($-90^\circ$)') 

451 

452 # Inset with Difference 

453 with sns.color_palette('bright'): 

454 if nr == 57 and kwargs.get('mirror'): 

455 bbox = (.11, .12, .34, .35) 

456 else: 

457 bbox = (.11, .59, .34, .35) 

458 inset2 = inset_axes(ax, width='100%', height='100%', 

459 bbox_to_anchor=bbox, 

460 bbox_transform=ax.transAxes) 

461 f_up = scipy.interpolate.interp1d(self.meas[nr].up.B, 

462 self.meas[nr].up.Bx9) 

463 f_down = scipy.interpolate.interp1d(self.meas[nr].down.B, 

464 self.meas[nr].down.Bx9) 

465 B = np.linspace(self.meas[nr].up.B.min(), 

466 self.meas[nr].up.B.max(), int(1e5)) 

467 downminusup = f_down(B) - f_up(B) 

468 inset2.plot([-max_b, max_b], [0, 0], '--', 

469 color='orange', linewidth=.75) 

470 inset2.plot(B, downminusup, color='green') 

471 inset2.set_xlim(-1000, 1000) 

472 inset2.set_title("Difference") 

473 if nr == 57: 

474 inset.set_yticklabels(['', '$0.0$', '', '$0.5$']) 

475 inset2.set_yticklabels(['', '$0.0$', '', '$0.5$']) 

476 

477 # if nr == 57 and not kwargs.get('mirror'): 

478 # ax.legend(loc='upper left')#, ncol=2) 

479 if not (nr == 57): 

480 ax.legend(loc='upper right') # , ncol=2) 

481 

482 plt.savefig("%s.pdf" % filename) 

483 

484 def plot_hloops2(self, to_show=[58, 59, 61, 62], 

485 filename='hloop-compare-3', **kwargs): 

486 """Outputs hloop-compare-3.pdf (not used anymore) 

487 

488 Args: 

489 to_show (TYPE, optional): DESCRIPTION. The default is a[85]+a[100]. 

490 filename (TYPE, optional): DESCRIPTION. The default is 

491 'hloop-compare-3'. 

492 **kwargs (TYPE): DESCRIPTION. 

493 

494 Returns: 

495 None.: 

496 """ 

497 fig, axes = plt.subplots(2, 2, figsize=(16, 12)) 

498 for i, nr in enumerate(to_show): 

499 ax = axes[i // 2][i % 2] 

500 self.m.style.set_style(size='talk', style='ticks', 

501 grid=True, latex=True) 

502 self.meas[nr] = Hloop(nr) 

503 self.meas[nr].plot_strayfield(ax) 

504 ax.set_xlim(-750, 750) 

505 if nr == 58: 

506 ax.set_ylim(self.meas[nr].down_fitted.Bx8.max(), 

507 self.meas[nr].up_fitted.Bx8.min()) 

508 with sns.color_palette('deep'): 

509 self.m.style.set_style(size='talk', style='ticks', 

510 grid=True, latex=True) 

511 if nr in [58, 59]: 

512 bbox = (.13, .02, .35, .35) 

513 else: 

514 bbox = (.65, .02, .35, .35) 

515 inset = inset_axes(ax, width='100%', height='90%', 

516 bbox_to_anchor=bbox, 

517 bbox_transform=ax.transAxes) 

518 max_b = self.meas[nr].up.B.max() 

519 inset.plot([-max_b, max_b], [0, 0], 'r--', linewidth=.75) 

520 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

521 inset.plot(B_ext, B_stray) 

522 inset.set_xlim(-750, 750) 

523 if not (nr in [58, 59]): 

524 inset.set_ylabel("$\Delta B_z\\;[\\mathrm{mT}]$") 

525 inset.set_title("Difference") 

526 inset.set_xticklabels([]) 

527 inset.set_xticks([]) 

528 

529 plt.savefig("%s.pdf" % filename) 

530 

531 def plot_hloops3(self, to_show=[139, 140], 

532 filename='hloop-repeat', 

533 xlim=(-350, 350), 

534 ylim=None, 

535 inset_xlim=(-30, 30), 

536 inset_ylim=(0.15, 1.25) 

537 ): 

538 """ 

539 Compares two measurements at the same Angle (repeated 

540 measurements). 

541 

542 Args: 

543 to_show (TYPE, optional): DESCRIPTION. The default is [139,140]. 

544 filename (TYPE, optional): DESCRIPTION. The default is 

545 'hloop-repeat'. 

546 xlim (TYPE, optional): DESCRIPTION. The default is (-350, 350). 

547 ylim: 

548 inset_xlim (TYPE, optional): DESCRIPTION. The default is (-30, 30). 

549 inset_ylim (TYPE, optional): DESCRIPTION. The default is (.15, 

550 1.25). 

551 

552 Returns: 

553 None.: 

554 """ 

555 self.m.style.set_style(size='talk', style='ticks', palette='Paired', 

556 grid=True, latex=True) 

557 fig, ax = plt.subplots(1, 1, figsize=(16, 12)) 

558 bmin, bmax = [], [] 

559 for i, nr in enumerate(to_show): 

560 # ax = axes[i//2][i%2] 

561 self.meas[nr] = Hloop(nr) 

562 self.meas[nr].plot_strayfield(ax, nolegend=True) 

563 ax.set_xlim(*xlim) 

564 bmin1, bmax1 = self.meas[nr].get_bhminmax() 

565 bmin.append(bmin1) 

566 bmax.append(bmax1) 

567 

568 if ylim: 

569 ax.set_ylim(*ylim) 

570 else: 

571 ax.set_ylim(np.min(bmin) - .05, np.max(bmax) + .05) 

572 ax.set_title("M%s/%s: %s ($%s^\\circ$)" % (to_show[0], to_show[1], 

573 self.meas[nr].info[ 

574 'Structure'].replace( 

575 '_', r'\_'), 

576 self.meas[nr].info[ 

577 'Angle'])) 

578 ax.legend(["M%d: Up" % to_show[0], "M%d: Down" % to_show[0], 

579 "M%d: Up" % to_show[1], "M%d: Down" % to_show[1], ]) 

580 y1, y2 = inset_ylim[0], inset_ylim[1] 

581 x1, x2 = inset_xlim[0], inset_xlim[1] 

582 ax.fill([x1, x1, x2, x2], [y1, y2, y2, y1], 'blue', alpha=.1) 

583 

584 with sns.color_palette('bright'): 

585 bbox = (.65, .055, .35, .3) 

586 inset = inset_axes(ax, width='100%', height='100%', 

587 bbox_to_anchor=bbox, 

588 bbox_transform=ax.transAxes) 

589 max_b = self.meas[nr].up.B.max() 

590 for nr in to_show: 

591 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield() 

592 inset.plot(B_ext, B_stray) 

593 inset.plot([-max_b, max_b], [0, 0], '--', linewidth=.75) 

594 inset.set_xlim(*xlim) 

595 inset.set_ylabel("$\Delta B_z\\;[\\mathrm{mT}]$") 

596 inset.set_title("Difference") 

597 

598 with sns.color_palette('Paired'): 

599 bbox = (.07, .45, .35, .35) 

600 inset2 = inset_axes(ax, width='100%', height='100%', 

601 bbox_to_anchor=bbox, 

602 bbox_transform=ax.transAxes) 

603 for nr in to_show: 

604 self.meas[nr].plot_strayfield(inset2, nolegend=True) 

605 inset2.set_xlim(*inset_xlim) 

606 inset2.set_ylim(*inset_ylim) 

607 inset2.set_title("") 

608 inset2.set_ylabel('') 

609 

610 with sns.color_palette('Paired'): 

611 bbox = (.65, .43, .35, .3) 

612 inset3 = inset_axes(ax, width='100%', height='100%', 

613 bbox_to_anchor=bbox, 

614 bbox_transform=ax.transAxes) 

615 self.plot_hloop_gradient3(inset3, nr=to_show, 

616 limit=inset_xlim[1], ) 

617 # inset3.set_xticklabels(['']) 

618 inset3.set_xlim(*inset_xlim) 

619 inset3.set_xlabel('') 

620 inset3.legend_.remove() 

621 

622 plt.savefig("%s.pdf" % filename) 

623 

624 def plot_hloops_compare_90(self, to_show=[414, 415], 

625 structure='plusses', 

626 filename='hloop-repeat-414', 

627 xlim=(-750, 750), 

628 ylim=(-.36, .76), 

629 inset_xlim=(-225, 225), 

630 inset_ylim=(-.35, .75), 

631 insets=[((.05, .05, .35, .35), ((-225, 225), (-.35, .75), 'blue', .1))], 

632 legend_loc='upper right', 

633 nograd=False, 

634 nodiff=False, 

635 figsize=(16, 12), 

636 ): 

637 """ 

638 Compares multiple measurements at 90 deg (repeated 

639 measurements). 

640 

641 Args: 

642 to_show (TYPE, optional): DESCRIPTION. The default is [414,415]. 

643 structure: 

644 filename (TYPE, optional): DESCRIPTION. The default is 

645 'hloop-repeat-414'. 

646 xlim (TYPE, optional): DESCRIPTION. The default is (-750, 750). 

647 ylim: 

648 inset_xlim (TYPE, optional): DESCRIPTION. The default is (-100, 

649 100). 

650 inset_ylim (TYPE, optional): DESCRIPTION. The default is (-1.25, 

651 .75). 

652 legend_loc: 

653 nograd: 

654 

655 Returns: 

656 None.: 

657 """ 

658 self.m.style.set_style(size='talk', style='ticks', 

659 palette='Paired', 

660 grid=True, latex=True) 

661 fig, ax = plt.subplots(1, 1, figsize=figsize) 

662 legend = [] 

663 if structure == 'plusses': 

664 column = 'Bx8' 

665 elif structure == 'crosses': 

666 column = 'Bx9' 

667 

668 for i, nr in enumerate(to_show): 

669 # ax = axes[i//2][i%2] 

670 self.meas[nr] = Hloop(nr) # Load measurement 

671 self.meas[nr].remove_zero() # Remove measurement Errors 

672 

673 self.meas[nr].plot_strayfield(ax, nolegend=True, 

674 show_plusses=( 

675 structure == 'plusses'), 

676 show_crosses=( 

677 structure == 'crosses')) 

678 ax.set_xlim(*xlim) 

679 

680 legend += ["M%d: Up" % nr, "M%d: Down" % nr] 

681 

682 m_numbers = '/'.join(map(str, to_show)) 

683 

684 if ylim: 

685 ax.set_ylim(*ylim) 

686 

687 self.m.style.set_style(size='talk', style='ticks', palette='Paired', 

688 grid=True, latex=True) 

689 ax.set_title("M%s: %s ($%s^\\circ$)" % (m_numbers, 

690 structure.capitalize(), 

691 self.meas[nr].info['Angle'])) 

692 

693 self.m.style.set_style(size='notebook', style='ticks', 

694 palette='Paired', 

695 grid=True, latex=True) 

696 all_insets = [] 

697 if not nodiff: 

698 with sns.color_palette('bright'): 

699 bbox = (.7, .06, .3, .3) 

700 inset = inset_axes(ax, width='100%', height='100%', 

701 bbox_to_anchor=bbox, 

702 bbox_transform=ax.transAxes) 

703 all_insets.append(inset) 

704 max_b = self.meas[nr].up.B.max() 

705 for i, nr in enumerate(to_show): 

706 if structure == 'plusses': 

707 B_ext, B_stray = self.meas[nr].get_downminusup_strayfield( 

708 fitted_data=True) 

709 else: 

710 up = self.meas[nr].up_fitted 

711 down = self.meas[nr].down_fitted 

712 f_up = scipy.interpolate.interp1d(up.B, up.Bx9) 

713 f_down = scipy.interpolate.interp1d(down.B, down.Bx9) 

714 B_ext = np.linspace(up.B.min(), up.B.max(), int(1e5)) 

715 B_stray = f_down(B_ext) - f_up(B_ext) 

716 if i == 3: 

717 inset.plot(B_ext, B_stray, color='orange') 

718 else: 

719 inset.plot(B_ext, B_stray) 

720 if i == 0: 

721 inset.plot([-max_b, max_b], [0, 0], '--', linewidth=.75) 

722 

723 inset.set_xlim(*xlim) 

724 inset.set_ylabel("$\Delta B_z\\;[\\mathrm{mT}]$") 

725 inset.set_title("Difference") 

726 

727 for bbox, (inset_xlim, inset_ylim, color, alpha) in insets: 

728 with sns.color_palette('Paired'): 

729 inset2 = inset_axes(ax, width='100%', height='100%', 

730 bbox_to_anchor=bbox, 

731 bbox_transform=ax.transAxes) 

732 all_insets.append(inset2) 

733 for i, nr in enumerate(to_show): 

734 inset2.plot(self.meas[nr].up_fitted.B, 

735 self.meas[nr].up_fitted[column]) 

736 inset2.plot(self.meas[nr].down_fitted.B, 

737 self.meas[nr].down_fitted[column]) 

738 inset2.set_xlim(*inset_xlim) 

739 inset2.set_ylim(*inset_ylim) 

740 

741 # Draw Area into big plot 

742 y1, y2 = inset_ylim[0], inset_ylim[1] 

743 x1, x2 = inset_xlim[0], inset_xlim[1] 

744 coords = [x1, x1, x2, x2], [y1, y2, y2, y1] 

745 inset2.fill(*coords, color, alpha=alpha) 

746 ax.fill(*coords, color, alpha=alpha) 

747 

748 if not nograd: 

749 with sns.color_palette('Paired'): 

750 bbox = (.08, .67, .27, .3) 

751 inset3 = inset_axes(ax, width='100%', height='100%', 

752 bbox_to_anchor=bbox, 

753 bbox_transform=ax.transAxes) 

754 all_insets.append(inset3) 

755 c = column.replace('B', 'V') 

756 self.plot_hloop_gradient3(inset3, to_show, limit=inset_xlim[1], 

757 column=c) 

758 inset3.set_xlim(*inset_xlim) 

759 inset3.set_xlabel('') 

760 inset3.legend_.remove() 

761 

762 sns.set('notebook') 

763 ax.legend(legend, loc=legend_loc, ncol=int(len(to_show) / 2)) 

764 

765 plt.savefig("%s.png" % filename) 

766 

767 return fig, (ax, all_insets) 

768 

769 def plot_hloops4(self, filename='hloop-parallel', 

770 figtitle="M57: $90^\\circ$ Parallel measurement", 

771 **kwargs): 

772 """Plots a single measurement (default: 90deg parallel) 

773 

774 Args: 

775 filename (TYPE, optional): DESCRIPTION. The default is 

776 'hloop-parallel'. 

777 figtitle (TYPE, optional): DESCRIPTION. The default is "M57: 

778 $90^\circ$ Parallel measurement". 

779 **kwargs (TYPE): DESCRIPTION. 

780 

781 Returns: 

782 None.: 

783 """ 

784 fig, ax = plt.subplots(1, 1, figsize=(16, 12)) 

785 self.m.style.set_style(size='talk', style='ticks', palette='Paired', 

786 grid=True, latex=True) 

787 # self.mset_factor(-1) 

788 # self.mfactor = 1 

789 

790 self.m.plot_strayfield(ax, figtitle=figtitle, 

791 show_crosses=False) 

792 self.m.up_fitted.Bx9 += .25 

793 self.m.down_fitted.Bx9 += .25 

794 ax.plot(self.m.up_fitted.B, self.m.up_fitted.Bx9, 

795 label='Crosses: Up (fitted)') 

796 ax.plot(self.m.down_fitted.B, self.m.down_fitted.Bx9, 

797 label='Crosses: Down (fitted)') 

798 ax.set_xlim(-750, 750) 

799 if kwargs.get('ylim'): 

800 ax.set_ylim(*kwargs.get('ylim')) 

801 else: 

802 ax.set_ylim(-.8, 1.8) 

803 ax.legend(loc='best') 

804 

805 with sns.color_palette('bright'): 

806 bbox = (.06, .46, .35, .23) 

807 inset = inset_axes(ax, width='100%', height='100%', 

808 bbox_to_anchor=bbox, 

809 bbox_transform=ax.transAxes) 

810 max_b = self.m.up.B.max() 

811 B_ext, B_stray = self.m.get_downminusup_strayfield() 

812 inset.plot([-max_b, max_b], [0, 0], '--', color='orange', 

813 linewidth=.75) 

814 inset.plot(B_ext, B_stray) 

815 inset.set_xlim(-750, 750) 

816 inset.set_title("Difference Plusses") 

817 

818 bbox = (.06, .06, .35, .22) 

819 inset2 = inset_axes(ax, width='100%', height='100%', 

820 bbox_to_anchor=bbox, 

821 bbox_transform=ax.transAxes) 

822 f_up = scipy.interpolate.interp1d(self.m.up.B, self.m.up.Bx9) 

823 f_down = scipy.interpolate.interp1d(self.m.down.B, self.m.down.Bx9) 

824 B = np.linspace(self.m.up.B.min(), self.m.up.B.max(), int(1e5)) 

825 downminusup = f_down(B) - f_up(B) 

826 inset2.plot([-max_b, max_b], [0, 0], '--', color='orange', 

827 linewidth=.75) 

828 inset2.plot(B, downminusup, color='green') 

829 inset2.set_xlim(-750, 750) 

830 inset2.set_title("Difference Crosses") 

831 

832 plt.savefig("%s.pdf" % filename) 

833 

834 def plot_cubes_trees(self): 

835 """Plots difference between RAW data from Cubes and Trees (1st 

836 Generation) 

837 

838 Returns: 

839 None.: 

840 """ 

841 self.m.style.set_style(size='talk', style='ticks', palette='deep', 

842 grid=True, latex=True) 

843 file_list = ['data/Data/%sdeg_%s' % (angle, struct) for 

844 angle in [90, -90] for 

845 struct in ['cubes', 'Trees'] 

846 ] 

847 

848 fig, axes = plt.subplots(2, 2, figsize=(16, 12)) 

849 comp = {} 

850 for i, f in enumerate(file_list): 

851 ax = axes[i // 2][i % 2] 

852 load_files = ['%s_%s.dat' % (f, direction) for 

853 direction in ['a', 'b']] 

854 comp[i] = Hloop(0, file_list=load_files) 

855 comp[i].set_factor(1e6) 

856 

857 ax.plot(comp[i].up.B, comp[i].up.Vx8, label='Up') 

858 ax.plot(comp[i].down.B, comp[i].down.Vx8, label='Down') 

859 

860 ax.set_ylabel("$V_x [\\mathrm{\\mu V}]$") 

861 ax.set_xlabel("$\\mu_0 H_{ext}$ $[\\mathrm{mT}]$") 

862 bmin, bmax, vmin, vmax = comp[i].get_minmax() 

863 ax.set_xlim(bmin, bmax) 

864 

865 if f.find('cubes') > 0: 

866 struct = 'Cubes' 

867 else: 

868 struct = "Trees" 

869 

870 ax.set_title("%s ($%s^\\circ$)" % (struct, f[10:13].strip('d'))) 

871 

872 with sns.color_palette('bright'): 

873 if i % 2 == 1: 

874 bbox = (.69, .7, .3, .3) 

875 else: 

876 bbox = (.12, .7, .29, .3) 

877 inset = inset_axes(ax, width='100%', height='100%', 

878 bbox_to_anchor=bbox, 

879 bbox_transform=ax.transAxes) 

880 max_b = self.m.up.B.max() 

881 B_ext, B_stray = comp[i].get_downminusup() 

882 inset.plot([-max_b, max_b], [0, 0], '--', color='orange', 

883 linewidth=.75) 

884 inset.plot(B_ext, B_stray) 

885 inset.set_xlim(bmin, bmax) 

886 # inset.set_title("Difference") 

887 

888 ax.legend(loc='lower left') 

889 

890 plt.savefig("compare-cubes-trees.pdf") 

891 

892 def plot_hloop_gradient(self, limit=50, filename='hloop-gradient'): 

893 """Plotting the gradient along the 

894 

895 Args: 

896 limit: 

897 filename: 

898 

899 Returns: 

900 None.: 

901 """ 

902 self.m.style.set_style(default=True, grid=True, 

903 style='ticks', 

904 size='talk', 

905 palette='deep', 

906 latex=True, ) 

907 

908 grad1 = [np.divide(np.diff(self.m.up.Vx8), np.diff(self.m.up.Time)), 

909 np.divide(np.diff(self.m.up.Vx9), np.diff(self.m.up.Time))] 

910 grad12 = [ 

911 np.divide(np.diff(self.m.down.Vx8), np.diff(self.m.down.Time)), 

912 np.divide(np.diff(self.m.down.Vx9), np.diff(self.m.down.Time))] 

913 

914 fig, axes = plt.subplots(2, 1, sharex=True) 

915 for i in range(2): 

916 ax = axes[i] 

917 g = grad1[i] 

918 g2 = grad12[i] 

919 

920 if i == 0: 

921 add = 'Plusses' 

922 else: 

923 add = 'Crosses' 

924 

925 ax.set_title('M57: Gradient (%s)' % add) 

926 x = self.m.up[:-1] 

927 ax.plot(x.B[x.B.abs() < limit], 

928 g[x.B.abs() < limit] * 1e6, 

929 label='Up (%s)' % add) 

930 x = self.m.down[:-1] 

931 ax.plot(x.B[x.B.abs() < limit], 

932 g2[x.B.abs() < limit] * 1e6, 

933 label='Down (%s)' % add) 

934 ax.set_ylabel('$dV_H/dt\; [\\mu\\mathrm{V/s}]$') 

935 ax.set_xlabel('$\\mu_0 H_{ext} [\\mathrm{mT}]$') 

936 

937 plt.savefig('%s.pdf' % filename) 

938 

939 def plot_hloop_gradient2(self, limit=50, filename='hloop-gradient'): 

940 """Plotting the gradient along the 

941 

942 Args: 

943 limit: 

944 filename: 

945 

946 Returns: 

947 None.: 

948 """ 

949 self.m.style.set_style(default=True, grid=True, 

950 style='ticks', 

951 size='talk', 

952 palette='deep', 

953 latex=True, ) 

954 

955 grad = [np.gradient(self.m.up.Vx8, np.diff(self.m.up.Time).mean()), 

956 np.gradient(self.m.down.Vx8, np.diff(self.m.down.Time).mean())] 

957 

958 fig, ax = plt.subplots() 

959 ax.set_title('M%s: Gradient (%s)' % (self.m.self.measurement_number, 

960 self.m.info['Structure'])) 

961 for i in range(2): 

962 g = grad[i] 

963 

964 if i == 0: 

965 x = self.m.up 

966 add = 'Up' 

967 else: 

968 x = self.m.down 

969 add = 'Down' 

970 

971 ax.plot(x.B[x.B.abs() < limit], 

972 g[x.B.abs() < limit] * 1e6, 

973 label='%s' % add) 

974 ax.set_ylabel('$dV_H/dt\; [\\mu\\mathrm{V/s}]$') 

975 ax.legend(loc='best') 

976 ax.set_xlabel('$\\mu_0 H_{ext} [\\mathrm{mT}]$') 

977 

978 plt.savefig('%s.pdf' % filename) 

979 

980 def plot_hloop_gradient3(self, ax, to_show=[139, 140], limit=50, 

981 column='Vx8'): 

982 """Plotting the gradient along the 

983 

984 Args: 

985 ax: 

986 to_show: 

987 limit: 

988 column: 

989 

990 Returns: 

991 None.: 

992 """ 

993 # self.m.style.set_style(default=True, grid=True, 

994 # style='ticks', 

995 # size='talk', 

996 # palette='Paired', 

997 # latex=True,) 

998 

999 limit = np.abs(limit) 

1000 

1001 ax.set_title('Gradient') 

1002 for nr in to_show: 

1003 self.m = self.meas[nr] 

1004 c = column 

1005 grad = [np.divide(np.diff(self.m.up[c]), np.diff(self.m.up.Time)), 

1006 np.divide(np.diff(self.m.down[c]), 

1007 np.diff(self.m.down.Time))] 

1008 for i in range(2): 

1009 g = grad[i] 

1010 

1011 if i == 0: 

1012 x = self.m.up[:-1] 

1013 direction = 'Up' 

1014 else: 

1015 x = self.m.down[:-1] 

1016 direction = 'Down' 

1017 

1018 ax.plot(x.B[x.B.abs() < limit], 

1019 g[x.B.abs() < limit] * 1e6, 

1020 label='M%s: %s' % (nr, direction)) 

1021 

1022 # ax.set_xlim(-limit, limit) 

1023 ax.set_ylabel('$dV_H/dt\; [\\mu\\mathrm{V/s}]$') 

1024 ax.legend(loc='best') 

1025 ax.set_xlabel('$\\mu_0 H_{ext} [\\mathrm{mT}]$') 

1026 

1027 def plot_hloop_temp(self): 

1028 """Plots the Temperature of a Hloop measurement. 

1029 

1030 Returns: 

1031 None.: 

1032 """ 

1033 

1034 self.m.style.set_style(default=True, grid=True, 

1035 style='ticks', 

1036 size='talk', 

1037 palette='deep', 

1038 latex=True, ) 

1039 

1040 fig, ax = plt.subplots() 

1041 ax.set_title( 

1042 'M%s: Sample Temperature' % self.m[self.measurement_number]) 

1043 

1044 ax.plot(self.m.up.B, (self.m.up['Sample Temp']), '-', label='Up') 

1045 ax.plot(self.m.down.B, (self.m.down['Sample Temp']), '-', label='Down') 

1046 

1047 ax.set_xlabel('$\\mu_0 H_{ext} [\\mathrm{mT}]$') 

1048 ax.set_ylabel('Temperature $[\\mathrm{mK}]$') 

1049 ax.legend(loc='best') 

1050 

1051 plt.savefig('hloop-90-temp.pdf') 

1052 

1053 #### Plot Static Fields 

1054 def plot_static_fields(self, filename='static-field-w-inset'): 

1055 """Plot the Signal Analyzer (SA) Data for static fields (not sweeping) 

1056 

1057 Returns: 

1058 None.: 

1059 """ 

1060 tmp = { 

1061 'Plusses (25 mT)': 360, 

1062 'Plusses (-25 mT)': 361, 

1063 'Plusses (-9.4 mT)': 282, 

1064 'Crosses (-9.4 mT)': 283, 

1065 'Plusses (0 T)': 281, 

1066 'Crosses (0 T)': 280, 

1067 'Empty (0 T)': 310, 

1068 # 'Crosses (250 mT)': 315, 

1069 } 

1070 lofm = {} 

1071 for i, j in tmp.items(): 

1072 lofm.update({j: ['%s' % i, {}]}) 

1073 

1074 self.eva.style.set_style(default=True, grid=True, 

1075 style='ticks', 

1076 size='talk', 

1077 palette='Paired', 

1078 latex=True, ) 

1079 

1080 fig, ax = self.eva.plot(lofm, 

1081 plot_settings=dict( 

1082 title='($90^\\circ$) Static Field', 

1083 xlim=(2e-2, 5e0), 

1084 ylim=(1e-7, 1e-3), 

1085 ), 

1086 f_settings=dict( 

1087 ymin=5e-5), 

1088 f2_settings=dict(disable=True), 

1089 ) 

1090 

1091 # ax = plt.gca() 

1092 with sns.color_palette('deep'): 

1093 inset = inset_axes(ax, width='100%', height='100%', 

1094 bbox_to_anchor=(.25, .58, .45, .4), 

1095 bbox_transform=ax.transAxes) 

1096 self.m.style.set_style(default=True, grid=True, 

1097 style='ticks', 

1098 size='talk', 

1099 palette='Paired', 

1100 latex=True) 

1101 self.m.plot_strayfield(inset, 'Strayfield Plusses', nolegend=True) 

1102 inset.legend(['Up', # ' ($-M_S \\rightarrow +M_S$)', 

1103 'Down']) # ' ($+M_S \\rightarrow -M_S$)']) 

1104 inset.grid(b=True, alpha=.4) 

1105 inset.set_xlim(-50, 50) 

1106 inset.set_ylim(-.65, .45) 

1107 

1108 def a(x): 

1109 return self.m.down.iloc[ 

1110 ((self.m.down.B - x) ** 2).idxmin()]['Bx8'] 

1111 

1112 def b(x): 

1113 return self.m.up.iloc[((self.m.up.B - x) ** 2).idxmin()]['Bx8'] 

1114 

1115 inset.plot((-25, -25), (a(-25), a(-25)), 'o', color='#000099', 

1116 alpha=.6) 

1117 inset.plot([25, 25], [b(25), b(25)], 'o', color='#9999FF', 

1118 alpha=.6) 

1119 inset.plot([-9.4, -9.4], [a(-9.4), a(-9.4)], 'o', color='green', 

1120 alpha=.6) 

1121 inset.plot([0], [a(0)], 'o', color='#FF3333', alpha=.8) 

1122 

1123 # ana.set_relative_yticks(inset) 

1124 inset.set_xticks(np.arange(-50, 51, 25)) 

1125 

1126 plt.savefig('{}.pdf'.format(filename)) 

1127 

1128 #### Sweeping Field 

1129 def first_sweeps(self, add=False, filename='vacant-sweeps'): 

1130 """First field sweeps (plus minus 50/75/100/etc.) 

1131 

1132 Args: 

1133 add: adding more data 

1134 filename: saving as pdf (default: vacant-sweeps) 

1135 

1136 Returns: 

1137 vacant-sweeps.pdf: 

1138 """ 

1139 self.m.style.set_style(default=True, grid=True, 

1140 size='talk', style='ticks', latex=True, 

1141 palette='deep') 

1142 

1143 lofm = {} 

1144 to_show = { 

1145 # 382: [(-25,25), 'Plusses', 5, {}], 

1146 362: [(-50, 50), 'Plusses', 2, {}], 

1147 363: [(-75, 75), 'Plusses', 2, {}], 

1148 364: [(-100, 100), 'Plusses', 2, {}], 

1149 366: [(-125, 125), 'Plusses', 2, {}], 

1150 365: [(-150, 150), 'Plusses', 2, {}], 

1151 # 352: [("-M_s \\rightarrow -25",25), 'Plusses', .1], 

1152 } 

1153 if add: 

1154 to_show.update({ 

1155 336: [(-500, 500), 'Plusses', 9.4, {}], 

1156 331: [('\\mathrm{C}\\,{%s}' % -100, 100), 'Crosses', 9.4, 

1157 {'linestyle': '--'}], 

1158 332: [('\\mathrm{C}\\,{%s}' % -300, 300), 'Crosses', 9.4, 

1159 {'linestyle': '--'}], 

1160 333: [('\\mathrm{C}\\,{%s}' % -750, 750), 'Crosses', 9.4, 

1161 {'linestyle': '--'}], 

1162 }) 

1163 

1164 for nr, content in to_show.items(): 

1165 lofm[nr] = ["$%s \\rightarrow %s\\;\\mathrm{mT}$" % ( 

1166 content[0][0], 

1167 content[0][1], 

1168 ), content[3]] 

1169 

1170 fig, ax = self.eva.plot(lofm, 

1171 # fit_range=(2e-2, 9e-1), 

1172 # show_fit=True, 

1173 plot_settings=dict( 

1174 title='($90^\\circ$) Field Sweeps (Inside the Hysteresis)', 

1175 xlim=(1e-2, 1e0), 

1176 ylim=(4e-7, 7e-2)), 

1177 f_settings=dict( 

1178 xmin=5e-2, 

1179 ymin=1e-5), 

1180 f2_settings=dict( 

1181 xmin=2e-2, 

1182 ymin=1e-2, 

1183 ), 

1184 ) 

1185 

1186 # Inset with Strayfield 

1187 if not add: 

1188 with sns.color_palette('deep'): 

1189 inset = inset_axes(ax, width='100%', height='100%', 

1190 bbox_to_anchor=(.74, .45, .25, .25), 

1191 bbox_transform=ax.transAxes) 

1192 # Plotting Lines for each measurement 

1193 y1, y2 = -1, 1 

1194 for nr, content in to_show.items(): 

1195 x1 = content[0][1] 

1196 inset.plot([x1, x1, -x1, -x1], [y1, y2, y2, y1]) 

1197 

1198 self.m.plot_strayfield(inset, 'Strayfield Plusses', 

1199 show_plusses=False, 

1200 show_crosses=False, 

1201 nolegend=True) 

1202 

1203 inset.plot(self.m.up_fitted.B, self.m.up_fitted.Bx8, '-', 

1204 color=(76 / 255, 114 / 255, 176 / 255), 

1205 linewidth=3, label='Up') 

1206 inset.plot(self.m.down_fitted.B, self.m.down_fitted.Bx8, 'r-', 

1207 color=(221 / 255, 132 / 255, 82 / 255), 

1208 linewidth=1.5, label='Down') 

1209 

1210 inset.legend(['Up', # ($-M_S \\rightarrow +M_S$)', 

1211 'Down']) # ($+M_S \\rightarrow -M_S$)']) 

1212 inset.grid(b=True, alpha=.4) 

1213 inset.set_xlim(-200, 200) 

1214 inset.set_ylim(-.65, .45) 

1215 inset.set_xticks([-200 + 50 * _ for _ in range(9)]) 

1216 inset.set_xticks([-175 + 50 * _ for _ in range(8)], minor=True) 

1217 inset.set_yticks([-0.25 + .5 * _ for _ in range(2)], 

1218 minor=True) 

1219 inset.grid(b=True, which='minor', color='#cccccc', 

1220 linestyle='-.', alpha=.3) 

1221 

1222 # X-Ticks (labels) 

1223 xt_labels = [] 

1224 for i in [-200 + 50 * _ for _ in range(9)]: 

1225 if i % 100 == 0: 

1226 xt_labels += ['$%s$' % i] 

1227 else: 

1228 xt_labels += [''] 

1229 inset.set_xticklabels(xt_labels) 

1230 

1231 # Inset showing fitted data 

1232 with sns.color_palette("deep"): 

1233 inset2 = inset_axes(ax, width='100%', height='100%', 

1234 bbox_to_anchor=(.44, .75, .3, .25), 

1235 bbox_transform=ax.transAxes) 

1236 inset3 = inset_axes(ax, width='100%', height='100%', 

1237 bbox_to_anchor=(.09, .09, .3, .25), 

1238 bbox_transform=ax.transAxes) 

1239 

1240 for nr, content in to_show.items(): 

1241 intercept, slope = self.eva[nr].fit(fit_range=(2e-2, 9e-1)) 

1242 voltage = content[0][1] 

1243 

1244 inset2.plot(voltage, 10 ** intercept, 'o') 

1245 inset3.plot(voltage, -slope, 'o') 

1246 

1247 inset2.set_xlabel('End field [$\mu_0 \mathrm{H_{ext}}$]') 

1248 inset2.set_ylabel('$S_{V_H} (f=1\\;$Hz$)$') 

1249 inset2.set_yscale('log') 

1250 inset2.set_yticks([8e-7, 9e-7, 1e-6, 2e-6]) 

1251 

1252 inset3.set_xlabel('End field [$\mu_0 \mathrm{H_{ext}}$]') 

1253 inset3.set_ylabel('$\\alpha$') 

1254 

1255 plt.savefig('%s.pdf' % filename) 

1256 

1257 def compare_voltages(self, filename='compare-voltages'): 

1258 """Compare different applied Voltages. 

1259 

1260 Returns: 

1261 compare-voltages.pdf: 

1262 """ 

1263 self.m.style.set_style(default=True, grid=True, 

1264 size='talk', style='ticks', latex=True, 

1265 palette='deep') 

1266 

1267 lofm = {} 

1268 to_show = {} 

1269 for i in range(1, 6): 

1270 to_show[i + 377] = i 

1271 

1272 for nr, content in to_show.items(): 

1273 lofm[nr] = ["$%s\\;\\mu\\mathrm{A}$" % ( 

1274 content 

1275 ), {}] 

1276 

1277 fig, ax = self.eva.plot(lofm, 

1278 # fit_range=(2e-2, 7e-1), 

1279 # show_fit=True, 

1280 plot_settings=dict( 

1281 title='($90^\\circ$) Field Sweeps (Different current amplitudes)', 

1282 xlim=(1e-2, 1e0), 

1283 ylim=(4e-7, 7e-2)), 

1284 f_settings=dict(disable=True, 

1285 xmin=5e-2, 

1286 ymin=1e-5), 

1287 f2_settings=dict( 

1288 xmin=1.5e-1, 

1289 ymin=2e-3, 

1290 ), 

1291 ) 

1292 

1293 # Inset with Strayfield 

1294 with sns.color_palette('deep'): 

1295 inset = inset_axes(ax, width='100%', height='100%', 

1296 bbox_to_anchor=(.07, .38, .26, .26), 

1297 bbox_transform=ax.transAxes) 

1298 self.m.plot_strayfield(inset, 'Strayfield Plusses', 

1299 nolegend=True, ) 

1300 inset.legend(['Up', # ($-M_S \\rightarrow +M_S$)', 

1301 'Down']) # ($+M_S \\rightarrow -M_S$)']) 

1302 inset.grid(b=True, alpha=.4) 

1303 inset.set_xlim(-50, 50) 

1304 inset.set_ylim(-.45, .65) 

1305 inset.set_xticks([-50 + 25 * _ for _ in range(5)]) 

1306 # inset.set_xticks([-45+10*_ for _ in range(10)], minor=True) 

1307 inset.grid(b=True, which='minor', color='#cccccc', 

1308 linestyle='-.', alpha=.3) 

1309 # inset.set_xlabel('') 

1310 inset.set_ylabel('') 

1311 

1312 y1, y2 = -1, 2 

1313 inset.fill([-25, -25, 25, 25], [y1, y2, y2, y1], 'blue', alpha=.1) 

1314 inset.annotate("", xy=(25, -.35), xytext=(-25, -.2), 

1315 arrowprops=dict(arrowstyle="->", color='blue')) 

1316 

1317 # Inset showing fitted data 

1318 with sns.color_palette("deep"): 

1319 inset2 = inset_axes(ax, width='100%', height='100%', 

1320 bbox_to_anchor=(.54, .75, .3, .25), 

1321 bbox_transform=ax.transAxes) 

1322 inset3 = inset_axes(ax, width='100%', height='100%', 

1323 bbox_to_anchor=(.3, .09, .3, .25), 

1324 bbox_transform=ax.transAxes) 

1325 

1326 for nr, content in to_show.items(): 

1327 intercept, slope = self.eva[nr].fit(fit_range=(2e-2, 7e-1)) 

1328 voltage = content 

1329 

1330 inset2.plot(voltage, 10 ** intercept, 'o') 

1331 inset3.plot(voltage, -slope, 'o') 

1332 

1333 inset2.set_xlabel('Current [$\\mu\\mathrm{A}$]') 

1334 inset2.set_ylabel('$S_{V_H} (f=1\\;$Hz$)$') 

1335 inset2.set_yscale('log') 

1336 

1337 inset3.set_xlabel('Current [$\\mu\\mathrm{A}$]') 

1338 inset3.set_ylabel('$\\alpha$') 

1339 

1340 plt.savefig('{}.pdf'.format(filename)) 

1341 

1342 def compare_sweeprates(self, filename='compare-sweeprates'): 

1343 """Compare different Sweeprates, fits the data and 

1344 

1345 Returns: 

1346 None.: 

1347 """ 

1348 self.m.style.set_style(default=True, grid=True, 

1349 size='talk', style='ticks', latex=True, 

1350 palette='deep') 

1351 

1352 lofm = {} 

1353 to_show = { 

1354 382: [("-M_s \\rightarrow -25", 25), 'Plusses', 5], 

1355 354: [("-M_s \\rightarrow -25", 25), 'Plusses', 2], 

1356 351: [("-M_s \\rightarrow -25", 25), 'Plusses', 1], 

1357 355: [("-M_s \\rightarrow -25", 25), 'Plusses', .5], 

1358 353: [("-M_s \\rightarrow -25", 25), 'Plusses', .25], 

1359 352: [("-M_s \\rightarrow -25", 25), 'Plusses', .1], 

1360 } 

1361 

1362 for nr, content in to_show.items(): 

1363 lofm[nr] = ["$%s\\;\\frac{\\mathrm{mT}}{\\mathrm{min}}$" % ( 

1364 content[2], 

1365 ), {}] 

1366 

1367 fig, ax = self.eva.plot(lofm, 

1368 # fit_range=(2e-2, 5e-1), 

1369 # show_fit=True, 

1370 plot_settings=dict( 

1371 title='($90^\\circ$) Field Sweeps (Compare different Sweep Rates)', 

1372 xlim=(1e-2, 1.6e0), 

1373 ylim=(4e-7, 5e-2)), 

1374 f_settings=dict( 

1375 xmin=5e-2, 

1376 ymin=1e-5), 

1377 f2_settings=dict( 

1378 xmin=1.5e-1, 

1379 ), 

1380 ) 

1381 

1382 ax = plt.gca() 

1383 # Inset with Strayfield 

1384 with sns.color_palette('deep'): 

1385 inset = inset_axes(ax, width='100%', height='90%', 

1386 bbox_to_anchor=(.1, .06, .3, .33), 

1387 bbox_transform=ax.transAxes) 

1388 self.m.plot_strayfield(inset, 'Strayfield Plusses', 

1389 nolegend=True, ) 

1390 inset.legend(['Up', # ($-M_S \\rightarrow +M_S$)', 

1391 'Down']) # ($+M_S \\rightarrow -M_S$)']) 

1392 inset.grid(b=True, alpha=.4) 

1393 inset.set_xlim(-50, 50) 

1394 inset.set_ylim(-.45, .65) 

1395 inset.set_xticks([-50 + 25 * _ for _ in range(5)]) 

1396 

1397 y1, y2 = -1, 2 

1398 inset.fill([-25, -25, 25, 25], [y1, y2, y2, y1], 'blue', alpha=.1) 

1399 inset.annotate("", xy=(25, -.35), xytext=(-25, -.2), 

1400 arrowprops=dict(arrowstyle="->", color='blue')) 

1401 

1402 # Inset showing fitted data 

1403 with sns.color_palette("deep"): 

1404 inset2 = inset_axes(ax, width='100%', height='100%', 

1405 bbox_to_anchor=(.5, .75, .3, .25), 

1406 bbox_transform=ax.transAxes) 

1407 

1408 for nr, content in to_show.items(): 

1409 intercept, slope = self.eva[nr].fit(fit_range=(2e-2, 5e-1)) 

1410 sweep_rate = content[2] 

1411 

1412 inset2.plot(sweep_rate, 10 ** intercept, 'o') 

1413 

1414 inset2.set_xlabel( 

1415 'Sweep Rate $\\left[\\frac{\\mathrm{mT}}{\\mathrm{min}}\\right]$') 

1416 inset2.set_ylabel('$S_{V_H} (f=1\\;$Hz$)$') 

1417 inset2.set_yscale('log') 

1418 

1419 # Only save if necessary 

1420 plt.savefig('{}.pdf'.format(filename)) 

1421 

1422 def fast_sweeprate(self, show_numbers=[320, 325, 323, 329, ], xlim=None, 

1423 filename='FastSR-1', pos2=False, 

1424 title='($90^\circ$) Field sweeps ($\\Delta B \\geq 1\\;\\mathrm{T}$)'): 

1425 """anas Fast Sweeps over large sweep ranges (1T) 

1426 

1427 Args: 

1428 show_numbers: 

1429 xlim: 

1430 filename (TYPE, optional): DESCRIPTION. The default is 'FastSR-1'. 

1431 pos2: 

1432 title: 

1433 

1434 Returns: 

1435 None.: 

1436 """ 

1437 to_show = { 

1438 320: [(2, 1), 'Empty', 9.4], 

1439 321: [(2, 1), 'Empty', 4.7], 

1440 325: [(2, 1), 'Crosses', 9.4], 

1441 326: [(2, 1), 'Crosses', 4.7], 

1442 323: [(1, -1), 'Empty', 9.4], 

1443 324: [(1, -1), 'Empty', 4.7], 

1444 329: [(1, -1), 'Crosses', 9.4], 

1445 322: [(.5, -.5), 'Empty', 9.4], 

1446 327: [(.5, -.5), 'Crosses', 9.4], 

1447 328: [(.5, -.5), 'Crosses', 4.7], 

1448 336: [(.5, -.5), 'Plusses', 9.4], 

1449 333: [(.75, -.75), 'Crosses', 9.4], 

1450 332: [(.3, -.3), 'Crosses', 9.4], 

1451 331: [(.1, -.1), 'Crosses', 9.4], 

1452 } 

1453 

1454 lofm = {} 

1455 for nr, content in to_show.items(): 

1456 if content[2] == 4.7: 

1457 continue 

1458 if not (nr in show_numbers): 

1459 continue 

1460 lofm[ 

1461 nr] = '$%s \\rightarrow %s$ T %s ($%s \\frac{\\mathrm{mT}}{\\mathrm{min}}$)' % ( 

1462 content[0][0], 

1463 content[0][1], 

1464 content[1], 

1465 content[2], 

1466 ) 

1467 

1468 self.m.style.set_style(default=True, grid=True, size='talk', 

1469 style='ticks', 

1470 latex=True, palette='Paired') 

1471 fig, ax = plt.subplots(figsize=(16, 12)) 

1472 for i, j in lofm.items(): 

1473 label = 'm%s: %s' % (i, j) 

1474 if False: 

1475 self.eva[i].plot(label=label, ax=ax, color='orange', 

1476 dont_set_plot_settings=True) 

1477 else: 

1478 self.eva[i].plot(label=label, ax=ax, 

1479 dont_set_plot_settings=True) 

1480 

1481 self.eva[i]._set_plot_settings(xlim=(1e-2, 1.6e0), ylim=(1e-7, 5e-2), 

1482 title=title, 

1483 grid=dict(which='minor', 

1484 color='#ffff99', 

1485 linestyle='--', alpha=.5)) 

1486 self.eva[i]._draw_oneoverf(ax, ymin=3e-4, xmin=2e-2, alpha=2, 

1487 plot_style='b--', an_color='blue') 

1488 # self.eva[i]._draw_oneoverf(ax, xmin=1e-2, ymin=1e-6) 

1489 plt.grid(b=True, which='minor', color='#cccccc', linestyle='-.', 

1490 alpha=.3) 

1491 

1492 # Inset with Strayfield 

1493 with sns.color_palette('deep'): 

1494 if pos2: 

1495 bbox = (.1, .1, .3, .25) 

1496 else: 

1497 bbox = (.32, .72, .3, .25) 

1498 inset = inset_axes(ax, width='100%', height='100%', 

1499 bbox_to_anchor=bbox, 

1500 bbox_transform=ax.transAxes) 

1501 

1502 self.m.plot_strayfield(inset, 'Strayfield Crosses', 

1503 nolegend=True, 

1504 show_plusses=False) 

1505 inset.grid(b=True, alpha=.4) 

1506 if xlim: 

1507 inset.set_xlim(*xlim) 

1508 else: 

1509 inset.set_xlim(-1000, 1000) 

1510 inset.set_ylim(-.8, -1.45) 

1511 

1512 if pos2: 

1513 inset.set_xticks([-300 + 200 * _ for _ in range(4)], 

1514 minor=True) 

1515 for color, x1 in [((202 / 255, 178 / 255, 214 / 255), 300), 

1516 ((106 / 255, 61 / 255, 154 / 255), 100)]: 

1517 y1, y2 = -2, 2 

1518 inset.plot([x1, x1, -x1, -x1], [y1, y2, y2, y1], 

1519 color=color) 

1520 # inset.fill([-500, -500, 500, 500], [y1, y2, y2, y1], 'blue', alpha=.1) 

1521 # inset.annotate("", xy=(25, .35), xytext=(-25, .2), 

1522 # arrowprops=dict(arrowstyle="->", color='blue')) 

1523 

1524 plt.savefig('%s.pdf' % filename) 

1525 

1526 def sv_temp_effect(self, filename='sv-temp-effect'): 

1527 self.m.style.set_style(default=True, grid=True, 

1528 size='talk', style='ticks', latex=True, 

1529 palette='deep') 

1530 

1531 lofm = {} 

1532 to_show = { 

1533 351: [("-M_s \\rightarrow -25", 25), 'Plusses', 1, 30], 

1534 355: [("-M_s \\rightarrow -25", 25), 'Plusses', 0.5, 25], 

1535 356: [("-M_s \\rightarrow -25", 25), 'Plusses', 0.5, 20], 

1536 357: [("-M_s \\rightarrow -25", 25), 'Plusses', 0.5, 15], 

1537 358: [("-M_s \\rightarrow -25", 25), 'Plusses', 0.5, 10], 

1538 359: [("-M_s \\rightarrow -25", 25), 'Plusses', 0.5, 5], 

1539 } 

1540 

1541 for nr, content in to_show.items(): 

1542 lofm[nr] = ['$%s\\;\mathrm{K}$' % ( 

1543 content[3], 

1544 ), {}] 

1545 # self.eva[nr].Vx *= grad 

1546 

1547 t = '($90^\\circ$) Field Sweeps (' + \ 

1548 'Temperature Effect; Sweeprate = $%s\\;{\\mathrm{mT}}/{\\mathrm{min}}$)' % ( 

1549 content[2]) 

1550 

1551 fig, ax = self.eva.plot(lofm, 

1552 # fit_range=(2e-2, 7e-1), 

1553 # show_fit=True, 

1554 plot_settings=dict( 

1555 title=t, 

1556 xlim=(1e-2, 1.6e0), 

1557 ylim=(6e-7, 5e-2) 

1558 ), 

1559 f_settings=dict(disable=True), 

1560 f2_settings=dict( 

1561 xmin=7e-2 

1562 ) 

1563 ) 

1564 

1565 # Inset with Strayfield 

1566 with sns.color_palette('deep'): 

1567 inset = inset_axes(ax, width='100%', height='90%', 

1568 bbox_to_anchor=(.75, .4, .25, .25), 

1569 bbox_transform=ax.transAxes) 

1570 self.m.plot_strayfield(inset, 'Strayfield Plusses', 

1571 nolegend=True, ) 

1572 inset.legend(['Up', 'Down'], 

1573 loc='upper right') 

1574 inset.grid(b=True, alpha=.4) 

1575 inset.set_xlim(-50, 50) 

1576 inset.set_ylim(-.45, .65) 

1577 inset.set_ylabel('') 

1578 

1579 y1, y2 = -1, 2 

1580 inset.fill([-25, -25, 25, 25], [y1, y2, y2, y1], 'blue', alpha=.1) 

1581 inset.annotate("", xy=(25, -.35), xytext=(-25, -.2), 

1582 arrowprops=dict(arrowstyle="->", color='blue')) 

1583 

1584 # Inset showing fitted data 

1585 with sns.color_palette("deep"): 

1586 inset2 = inset_axes(ax, width='100%', height='100%', 

1587 bbox_to_anchor=(.5, .75, .3, .25), 

1588 bbox_transform=ax.transAxes) 

1589 inset3 = inset_axes(ax, width='100%', height='100%', 

1590 bbox_to_anchor=(.1, .09, .3, .3), 

1591 bbox_transform=ax.transAxes) 

1592 

1593 for nr, content in to_show.items(): 

1594 intercept, slope = self.eva[nr].fit(fit_range=(2e-2, 7e-1)) 

1595 temp = content[3] 

1596 

1597 inset2.plot(temp, 10 ** intercept, 'o') 

1598 inset3.plot(temp, -slope, 'o') 

1599 

1600 inset2.set_xlabel('Temperature [$\mathrm{K}$]') 

1601 inset2.set_ylabel('$S_{V_H} (f=1\\;$Hz$)$') 

1602 inset2.set_yscale('log') 

1603 inset2.set_xticks([5 + 10 * _ for _ in range(3)], minor=True) 

1604 

1605 inset3.set_xlabel('Temperature [$\mathrm{K}$]') 

1606 inset3.set_ylabel('$\\alpha$') 

1607 inset3.set_xticks([5 + 10 * _ for _ in range(3)], minor=True) 

1608 

1609 # Only save if necessary 

1610 plt.savefig('{}.pdf'.format(filename)) 

1611 

1612 def multiple_fspans(self, filename='multiple-fspans'): 

1613 self.m.style.set_style(default=True, grid=True, 

1614 size='talk', style='ticks', latex=True, 

1615 palette='Paired') 

1616 

1617 lofm = {} 

1618 to_show = { 

1619 340: [(25, -25), 'Empty', 0.46, {}], 

1620 349: [("-25", 25), 'Empty', 0.5, {}], 

1621 338: [(25, -25), 'Plusses', 0.46, {}], 

1622 342: [("+M_s \\rightarrow 25 \\rightarrow 8.3", -25), 'Plusses', 

1623 +0.11, {}], 

1624 343: [("-M_s \\rightarrow -25 \\rightarrow -8.3", 25), 'Plusses', 

1625 0.11, {'color': 'red'}], 

1626 } 

1627 

1628 for nr, content in to_show.items(): 

1629 if content[2] == 9.4: 

1630 continue 

1631 lofm[nr] = ['$%s \\rightarrow %s$ mT %s ($%s \\frac{mT}{min}$)' % ( 

1632 content[0][0], 

1633 content[0][1], 

1634 content[1], 

1635 content[2], 

1636 ), content[3]] 

1637 

1638 self.eva.plot(lofm, 

1639 plot_settings=dict( 

1640 title='($90^\\circ$) Field Sweeps ($B = \\pm 25 mT$)', 

1641 xlim=(6e-3, 1.6e0), 

1642 # ylim=() 

1643 ), 

1644 f_settings=dict(disable=True, 

1645 xmin=5e-2, 

1646 ymin=1e-5), 

1647 f2_settings=dict( 

1648 xmin=1e-2, ) 

1649 ) 

1650 

1651 ax = plt.gca() 

1652 with sns.color_palette('Dark2'): 

1653 inset = inset_axes(ax, width='100%', height='90%', 

1654 bbox_to_anchor=(.7, .44, .3, .3), 

1655 bbox_transform=ax.transAxes) 

1656 self.m.plot_strayfield(inset, 'Strayfield Plusses', 

1657 show_crosses=False, 

1658 nolegend=True) 

1659 inset.legend(['Up', 'Down']) 

1660 inset.grid(b=True, alpha=.4) 

1661 s = 30 

1662 inset.set_xlim(-s, s) 

1663 inset.set_ylim(-.45, .65) 

1664 s = 20 

1665 inset.set_xticks(np.linspace(-s, s, 5)) 

1666 inset.set_xticks([-s - 5 + 10 * _ for _ in range(6)], minor=True) 

1667 

1668 y1, y2 = -1, 2 

1669 inset.fill([-25, -25, -8.3, -8.3], [y1, y2, y2, y1], 'red', 

1670 alpha=.2) 

1671 inset.fill([25, 25, 8.3, 8.3], [y1, y2, y2, y1], 'green', alpha=.2) 

1672 inset.fill([8.3, 8.3, -8.3, -8.3], [y1, y2, y2, y1], 'blue', 

1673 alpha=.05) 

1674 # inset.plot([8.3, 8.3], [y1, y2], 'b-.', alpha=.8) 

1675 

1676 # Only save if necessary 

1677 plt.savefig('{}.pdf'.format(filename)) 

1678 

1679 def negative_sweeps(self): 

1680 """Testing without file output. 

1681 

1682 Returns: 

1683 None.: 

1684 """ 

1685 self.m.style.set_style(default=True, grid=True, 

1686 size='talk', style='ticks', latex=True, 

1687 palette='Paired') 

1688 lofm = {} 

1689 to_show = { 

1690 340: [(25, -25), 'Empty', 0.46, {}], 

1691 338: [(25, -25), 'Plusses', 0.46, {}], 

1692 348: [("-M_s \\rightarrow 36.56", -291), 'Empty', 0.5, {}], 

1693 347: [("-M_s \\rightarrow 36.56", -291), 'Plusses', 0.5, {}], 

1694 } 

1695 

1696 for nr, content in to_show.items(): 

1697 if content[2] == 9.4: 

1698 continue 

1699 options = content[3] 

1700 lofm[nr] = ['$%s \\rightarrow %s$ mT %s ($%s \\frac{mT}{min}$)' % ( 

1701 content[0][0], 

1702 content[0][1], 

1703 content[1], 

1704 content[2], 

1705 ), options] 

1706 

1707 fig, ax = self.eva.plot(lofm, 

1708 plot_settings=dict( 

1709 title='($90^\\circ$) Field Sweeps (measurement Plan \#2)', 

1710 xlim=(6e-3, 1.6e0), 

1711 # ylim=() 

1712 ), 

1713 f_settings=dict( 

1714 xmin=6e-3, 

1715 ymin=1e-5)) 

1716 

1717 with sns.color_palette('muted'): 

1718 inset = inset_axes(ax, width='100%', height='90%', 

1719 bbox_to_anchor=(.28, .73, .29, .24), 

1720 bbox_transform=ax.transAxes) 

1721 self.m.plot_strayfield(inset, 'Strayfield', nolegend=True) 

1722 inset.legend(['Up ($-M_S \\rightarrow +M_S$)', 

1723 'Down ($+M_S \\rightarrow -M_S$)']) 

1724 inset.grid(b=True, alpha=.4) 

1725 inset.set_xlim(-650, 50) 

1726 inset.set_ylim(-.45, .65) 

1727 

1728 y1, y2 = -1, 2 

1729 inset.fill([-25, -25, 25, 25], [y1, y2, y2, y1], 'blue', alpha=.1) 

1730 inset.fill([-291.13, -291.13, 36.56, 36.56], [y1, y2, y2, y1], 

1731 'green', alpha=.1) 

1732 inset.fill([-611, -611, -443, -443], [y1, y2, y2, y1], 'orange', 

1733 alpha=.1) 

1734 inset.fill([-291, -291, -443, -443], [y1, y2, y2, y1], 'darkred', 

1735 alpha=.1) 

1736 

1737 def measplan12(self): 

1738 c1 = sns.color_palette("hls", 6) 

1739 # sns.color_palette("Reds_r", 14) 

1740 self.m.style.set_style(default=True, grid=True, 

1741 size='talk', style='ticks', latex=True, 

1742 palette='deep') 

1743 sns.set_palette(c1) 

1744 lofm = {} 

1745 to_show = { 

1746 383: [("+M_s \\rightarrow 25", -25), 'Plusses', +0.5, {}], 

1747 384: [("-25", -75), 'Plusses', +0.5, 

1748 {'color': 'orange', 'linestyle': '--'}], 

1749 } 

1750 

1751 for i in range(6): 

1752 to_show.update( 

1753 { 

1754 (385 + i): [("+M_s \\rightarrow %d" % (-(i * 50 + 25)), 

1755 (-(i * 50 + 25) - 50)), 'Plusses', +0.5, {}], 

1756 } 

1757 ) 

1758 

1759 for nr, content in to_show.items(): 

1760 if content[2] == 9.4: 

1761 continue 

1762 options = content[3] 

1763 lofm[nr] = ['$%s \\rightarrow %s\;\mathrm{mT}$' % ( 

1764 content[0][0], 

1765 content[0][1], 

1766 ), options] 

1767 

1768 fig, ax = self.eva.plot(lofm, 

1769 plot_settings=dict( 

1770 title='($90^\\circ$) Field Sweeps (Plusses $0.5\;\mathrm{mT}/\mathrm{min}$)', 

1771 xlim=(1e-2, 1.6e0), 

1772 ylim=(3e-3, 6e-7) 

1773 ), 

1774 f_settings=dict( 

1775 xmin=1e-2, 

1776 ymin=3e-5), 

1777 f2_settings=dict( # disable=True 

1778 xmin=2e-2, 

1779 plot_style='k-.', 

1780 an_color='k' 

1781 ), 

1782 ) 

1783 

1784 ax = plt.gca() 

1785 with sns.color_palette(c1): 

1786 inset = inset_axes(ax, width='100%', height='90%', 

1787 bbox_to_anchor=(.4, .73, .29, .24), 

1788 bbox_transform=ax.transAxes) 

1789 self.m.plot_strayfield(inset, 'Strayfield', nolegend=True) 

1790 inset.legend(['Up ($-M_S \\rightarrow +M_S$)', 

1791 'Down ($+M_S \\rightarrow -M_S$)']) 

1792 inset.grid(b=True, alpha=.4) 

1793 inset.set_xlim(-650, 50) 

1794 inset.set_ylim(-.45, .65) 

1795 

1796 y1, y2 = -1, 2 

1797 for j in [25] + [-25 - 50 * i for i in range( 

1798 5)]: # + [-300-50*i for i in range(5)] + [-575]: 

1799 inset.fill([j, j, j - 50, j - 50], [y1, y2, y2, y1], alpha=.4) 

1800 # for j in [-300-50*i for i in range(5)] + [-575]: 

1801 # inset.fill([j, j, j-50, j-50], [y1, y2, y2, y1], alpha=.4) 

1802 ax.annotate('Without Saturation', (1.2e-2, 1e-3), color='orange', 

1803 rotation=-55) 

1804 ax.annotate('With Saturation', (1.01e-2, .8e-3), color='yellow', 

1805 rotation=-37) 

1806 

1807 plt.savefig('self.measplan12-1.pdf') 

1808 

1809 def measplan12_2(self): 

1810 c1 = sns.color_palette("hls", 7) 

1811 # sns.color_palette("Reds_r", 14) 

1812 self.m.style.set_style(default=True, grid=True, 

1813 size='talk', style='ticks', latex=True, 

1814 palette='deep') 

1815 sns.set_palette(c1) 

1816 lofm = {} 

1817 to_show = {} 

1818 for i, j in enumerate([-(_ * 50 + 300) for _ in range(5)] + [-575]): 

1819 to_show.update( 

1820 { 

1821 (391 + i): [("+M_s \\rightarrow %d" % (j), (j - 50)), 

1822 'Plusses', +0.5, {}], 

1823 } 

1824 ) 

1825 

1826 j = -625 

1827 to_show[397] = [("-M_s \\rightarrow %d" % (j), (j + 50)), 'Plusses', 

1828 +0.5, {}] 

1829 

1830 for nr, content in to_show.items(): 

1831 if content[2] == 9.4: 

1832 continue 

1833 options = content[3] 

1834 lofm[nr] = ['$%s \\rightarrow %s\;\mathrm{mT}$' % ( 

1835 content[0][0], 

1836 content[0][1], 

1837 ), options] 

1838 

1839 fig, ax = self.eva.plot(lofm, 

1840 plot_settings=dict( 

1841 title='($90^\\circ$) Field Sweeps (Plusses $0.5\;\mathrm{mT}/\mathrm{min}$)', 

1842 xlim=(1e-2, 1.6e0), 

1843 ylim=(2e-4, 2e-7) 

1844 ), 

1845 f_settings=dict( 

1846 xmin=1e-2, 

1847 ymin=2e-5), 

1848 f2_settings=dict( # disable=True 

1849 xmin=1e-2, 

1850 plot_style='k-.', 

1851 an_color='k', 

1852 disable=True, 

1853 ), 

1854 ) 

1855 

1856 with sns.color_palette(c1): 

1857 inset = inset_axes(ax, width='100%', height='90%', 

1858 bbox_to_anchor=(.4, .73, .29, .24), 

1859 bbox_transform=ax.transAxes) 

1860 self.m.plot_strayfield(inset, 'Strayfield Plusses', nolegend=True) 

1861 inset.legend(['Up ($-M_S \\rightarrow +M_S$)', 

1862 'Down ($+M_S \\rightarrow -M_S$)']) 

1863 inset.grid(b=True, alpha=.4) 

1864 inset.set_xlim(-650, 50) 

1865 inset.set_ylim(-.45, .65) 

1866 

1867 y1, y2 = -1, 2 

1868 for j in [-300 - 50 * i for i in range(5)] + [-575]: 

1869 inset.fill([j, j, j - 50, j - 50], [y1, y2, y2, y1], alpha=.4) 

1870 

1871 plt.savefig('self.measplan12-2.pdf') 

1872 

1873 def measplan12_full(self, name='measplan12-full'): 

1874 """measurement Plan #12 All 14 measurements in one Graph. 

1875 

1876 Args: 

1877 name: 

1878 """ 

1879 # c1 = sns.color_palette("twilight", 14) 

1880 c1 = sns.color_palette("hls", 14) 

1881 self.m.style.set_style(default=True, grid=True, 

1882 size='talk', style='ticks', latex=True) 

1883 sns.set_palette(c1) 

1884 

1885 # Choosing measurement Numbers to plot 

1886 lofm = {} 

1887 to_show = { 

1888 383: [("+M_s \\rightarrow 25", -25), 'Plusses', +0.5, {}], 

1889 384: [("-25", -75), 'Plusses', +0.5, 

1890 {'color': 'orange', 'linestyle': '--'}], 

1891 } 

1892 

1893 for i in range(6): 

1894 to_show.update( 

1895 { 

1896 (385 + i): [("+M_s \\rightarrow %d" % (-(i * 50 + 25)), 

1897 (-(i * 50 + 25) - 50)), 'Plusses', +0.5, {}], 

1898 } 

1899 ) 

1900 

1901 for i, j in enumerate([-(_ * 50 + 300) for _ in range(5)] + [-575]): 

1902 to_show.update( 

1903 { 

1904 (391 + i): [("+M_s \\rightarrow %d" % (j), (j - 50)), 

1905 'Plusses', +0.5, {}], 

1906 } 

1907 ) 

1908 

1909 j = -625 

1910 to_show[397] = [("-M_s \\rightarrow %d" % (j), (j + 50)), 'Plusses', 

1911 +0.5, {}] 

1912 

1913 # Converting them to a list of measurements (lofm) 

1914 for nr, content in to_show.items(): 

1915 if content[2] == 9.4: 

1916 continue 

1917 options = content[3] 

1918 lofm[nr] = ['$%s \\rightarrow %s\;\mathrm{mT}$' % ( 

1919 content[0][0], 

1920 content[0][1], 

1921 ), options] 

1922 

1923 fig, ax = self.eva.plot(lofm, 

1924 plot_settings=dict( 

1925 title='($90^\\circ$) Field Sweeps (Plusses;' + \ 

1926 ' $\\Delta B = 50\\mathrm{mT}$;' + \ 

1927 ' $0.5\\;\\mathrm{mT}/\\mathrm{min}$)', 

1928 xlim=(1e-2, 1.6e0), 

1929 ylim=(5e-2, 5e-8), 

1930 legend_settings=dict(loc='best', ncol=2) 

1931 ), 

1932 f_settings=dict( 

1933 xmin=1e-2, 

1934 ymin=3e-5), 

1935 f2_settings=dict( # disable=True 

1936 xmin=2e-2, 

1937 plot_style='k-.', 

1938 an_color='k' 

1939 ), 

1940 ) 

1941 

1942 with sns.color_palette(c1): 

1943 inset = inset_axes(ax, width='100%', height='100%', 

1944 bbox_to_anchor=(.07, .06, .34, .26), 

1945 bbox_transform=ax.transAxes) 

1946 self.m.plot_strayfield(inset, 

1947 'Strayfield Plusses', 

1948 show_plusses=False, 

1949 show_crosses=False, 

1950 nolegend=True) 

1951 

1952 y1, y2 = -1, 2 

1953 for j in [25 - 50 * i for i in range(6)] + \ 

1954 [-300 - 50 * i for i in range(5)] + [-575]: 

1955 inset.fill([j, j, j - 50, j - 50], [y1, y2, y2, y1], alpha=.8) 

1956 

1957 inset.plot(self.m.up_fitted.B, self.m.up_fitted.Bx8, 'b-', 

1958 linewidth=1.5, label='Up') 

1959 inset.plot(self.m.down_fitted.B, self.m.down_fitted.Bx8, 'r-', 

1960 linewidth=3, label='Down') 

1961 

1962 inset.legend(loc='best') 

1963 

1964 inset.grid(b=True, alpha=.4) 

1965 inset.set_xlim(-650, 50) 

1966 inset.set_ylim(-.45, .65) 

1967 inset.set_xlabel('') 

1968 inset.set_ylabel('') 

1969 

1970 ax.annotate('Without Saturation', (1.2e-2, 5e-4), color='orange', 

1971 rotation=-55) 

1972 ax.annotate('With Saturation', (1.01e-2, 4e-4), color='orange', 

1973 rotation=-35) 

1974 

1975 plt.savefig('%s.pdf' % name) 

1976 

1977 def set_size(self, width_pt, fraction=1, subplots=(1, 1)): 

1978 """Set figure dimensions to sit nicely in our document. 

1979  

1980 Source: https://jwalton.info/Matplotlib-latex-PGF/ 

1981 

1982 Parameters 

1983 ---------- 

1984 width_pt: float 

1985 Document width in points 

1986 fraction: float, optional 

1987 Fraction of the width which you wish the figure to occupy 

1988 subplots: array-like, optional 

1989 The number of rows and columns of subplots. 

1990 Returns 

1991 ------- 

1992 fig_dim: tuple 

1993 Dimensions of figure in inches 

1994 """ 

1995 # Width of figure (in pts) 

1996 fig_width_pt = width_pt * fraction 

1997 # Convert from pt to inches 

1998 inches_per_pt = 1 / 72.27 

1999 

2000 # Golden ratio to set aesthetic figure height 

2001 golden_ratio = (5 ** .5 - 1) / 2 

2002 

2003 # Figure width in inches 

2004 fig_width_in = fig_width_pt * inches_per_pt 

2005 # Figure height in inches 

2006 fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1]) 

2007 

2008 return (fig_width_in, fig_height_in)