Skip to content

Commit 0d54082

Browse files
committed
Pass all plot data as a dict
1 parent fa65af7 commit 0d54082

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

docs/user-guide/sns-instruments/vanadium_processing.ipynb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
28+
"import plopp as pp\n",
2829
"import scipp as sc\n",
2930
"import scippneutron as scn\n",
3031
"import scippneutron.peaks\n",
@@ -275,11 +276,26 @@
275276
" ), strict=True)\n",
276277
"\n",
277278
" # 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",
279298
" ax = fig.ax\n",
280-
" xlim = ax.get_xlim()\n",
281-
" ylim = ax.get_ylim()\n",
282-
" removed.plot(ax=ax, c='C2')\n",
283299
"\n",
284300
" # Initial estimates\n",
285301
" for estimate, result in zip(peak_estimates, fit_results, strict=True):\n",
@@ -308,17 +324,6 @@
308324
" if not result.success:\n",
309325
" ax.text(left.value, hi, result.message.split(\":\", 1)[0])\n",
310326
"\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",
322327
" return fig"
323328
]
324329
},

0 commit comments

Comments
 (0)