|
25 | 25 | "metadata": {}, |
26 | 26 | "outputs": [], |
27 | 27 | "source": [ |
| 28 | + "import plopp as pp\n", |
28 | 29 | "import scipp as sc\n", |
29 | 30 | "import scippneutron as scn\n", |
30 | 31 | "import scippneutron.peaks\n", |
|
275 | 276 | " ), strict=True)\n", |
276 | 277 | "\n", |
277 | 278 | " # The actual data\n", |
278 | | - " fig = data.plot(c=\"C0\")\n", |
| 279 | + " plot_data = {'data': data, 'removed': removed}\n", |
| 280 | + " linestyles = {}\n", |
| 281 | + " markers = {}\n", |
| 282 | + " colors = {'data': 'C0','removed': 'C2'}\n", |
| 283 | + "\n", |
| 284 | + " # Overlay with fit models evaluated at optimized parameters\n", |
| 285 | + " for i, result in enumerate(fit_results):\n", |
| 286 | + " if all(not sc.isnan(param).value for param in result.popt.values()):\n", |
| 287 | + " best_fit = data[data.dim, result.window[0] : result.window[1]].copy(deep=False)\n", |
| 288 | + " best_fit.coords[best_fit.dim] = sc.midpoints(best_fit.coords[best_fit.dim])\n", |
| 289 | + " best_fit.data = result.eval_model(best_fit.coords[best_fit.dim])\n", |
| 290 | + "\n", |
| 291 | + " key = f'result_{i}'\n", |
| 292 | + " plot_data[key] = best_fit\n", |
| 293 | + " linestyles[key] = '-'\n", |
| 294 | + " markers[key] = \"none\"\n", |
| 295 | + " colors[key] = \"C1\"\n", |
| 296 | + "\n", |
| 297 | + " fig = pp.plot(plot_data, ls=linestyles, marker=markers, c=colors, legend=False)\n", |
279 | 298 | " ax = fig.ax\n", |
280 | | - " xlim = ax.get_xlim()\n", |
281 | | - " ylim = ax.get_ylim()\n", |
282 | | - " removed.plot(ax=ax, c='C2')\n", |
283 | 299 | "\n", |
284 | 300 | " # Initial estimates\n", |
285 | 301 | " for estimate, result in zip(peak_estimates, fit_results, strict=True):\n", |
|
308 | 324 | " if not result.success:\n", |
309 | 325 | " ax.text(left.value, hi, result.message.split(\":\", 1)[0])\n", |
310 | 326 | "\n", |
311 | | - " # Overlay with fit models evaluated at optimized parameters\n", |
312 | | - " for result in fit_results:\n", |
313 | | - " if all(not sc.isnan(param).value for param in result.popt.values()):\n", |
314 | | - " best_fit = data[data.dim, result.window[0] : result.window[1]].copy(deep=False)\n", |
315 | | - " best_fit.coords[best_fit.dim] = sc.midpoints(best_fit.coords[best_fit.dim])\n", |
316 | | - " best_fit.data = result.eval_model(best_fit.coords[best_fit.dim])\n", |
317 | | - " best_fit.plot(ax=ax, c=\"C1\", ls=\"-\", marker=\"none\")\n", |
318 | | - "\n", |
319 | | - " ax.set_xlim(xlim)\n", |
320 | | - " # allocate extra space at the top for annotations\n", |
321 | | - " ax.set_ylim((ylim[0], ylim[1] * 1.05))\n", |
322 | 327 | " return fig" |
323 | 328 | ] |
324 | 329 | }, |
|
0 commit comments