diff --git a/EasyReflectometry/plot.py b/EasyReflectometry/plot.py index 3790c461..ce77a864 100644 --- a/EasyReflectometry/plot.py +++ b/EasyReflectometry/plot.py @@ -1,14 +1,13 @@ __author__ = 'github.com/arm61' import scipp as sc -import ipympl import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec color_cycle = plt.rcParams['axes.prop_cycle'].by_key()['color'] -def plot(data: sc.Dataset) -> ipympl.backend_nbagg.Canvas: +def plot(data: sc.Dataset): """ A general plotting function for EasyReflectometry. @@ -17,53 +16,57 @@ def plot(data: sc.Dataset) -> ipympl.backend_nbagg.Canvas: :returns: The plot canvas. """ if len([i for i in list(data.keys()) if 'SLD' in i]) == 0: + plot_sld = False fig = plt.figure(figsize=(5, 3)) gs = GridSpec(1, 1, figure=fig) else: + plot_sld = True fig = plt.figure(figsize=(5, 6)) gs = GridSpec(2, 1, figure=fig) ax2 = fig.add_subplot(gs[1, 0]) ax1 = fig.add_subplot(gs[0, 0]) refl_nums = [k[3:] for k, v in data.coords.items() if 'Qz' == k[:2]] - for i, name in enumerate(refl_nums): - copy = data[f'R_{name}'].copy() + for i, refl_num in enumerate(refl_nums): + copy = data[f'R_{refl_num}'].copy() copy.data *= sc.scalar(10.**i, unit=copy.unit) - sc.plot(copy, - ax=ax1, - norm='log', - linestyle='', - marker='.', - color=color_cycle[i]) + copy.coords[f'Qz_{refl_num}'].variances = None + sc.plot( + copy, + ax=ax1, + norm='log', + linestyle='', + marker='.', + color=color_cycle[i] + ) try: - copy = data[f'R_{name}_model'].copy() + copy = data[f'R_{refl_num}_model'].copy() copy.data *= sc.scalar(10.**float(i)) - sc.plot(copy, - ax=ax1, - norm='log', - linestyle='--', - color=color_cycle[i], - marker='') + copy.coords[f'Qz_{refl_num}'].variances = None + sc.plot( + copy, + ax=ax1, + norm='log', + linestyle='--', + color=color_cycle[i], + marker='' + ) except KeyError: pass ax1.autoscale(True) ax1.relim() ax1.autoscale_view() - for i, name in enumerate(refl_nums): - try: - copy = data[f'SLD_{name}'].copy() + if plot_sld: + for i, refl_num in enumerate(refl_nums): + copy = data[f'SLD_{refl_num}'].copy() copy.data += sc.scalar(10. * i, unit=copy.unit) - sc.plot(data[f'SLD_{name}'], - ax=ax2, - linestyle='-', - color=color_cycle[i], - marker='') - except KeyError: - pass - try: + sc.plot( + data[f'SLD_{refl_num}'], + ax=ax2, + linestyle='-', + color=color_cycle[i], + marker='' + ) ax2.autoscale(True) ax2.relim() ax2.autoscale_view() - except UnboundLocalError: - pass - return fig.canvas diff --git a/docs/monolayer.ipynb b/docs/monolayer.ipynb index 607532f5..d4fdea9c 100644 --- a/docs/monolayer.ipynb +++ b/docs/monolayer.ipynb @@ -12,6 +12,14 @@ "First, we will import the relevant packages and functions." ] }, + { + "cell_type": "markdown", + "id": "e46c0e41", + "metadata": {}, + "source": [ + "First configure matplotlib to place figures in notebook and import needed modules" + ] + }, { "cell_type": "code", "execution_count": null, @@ -19,6 +27,8 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import EasyReflectometry\n", "import refnx\n", "from EasyReflectometry.data import load\n", @@ -441,7 +451,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/docs/multi_contrast.ipynb b/docs/multi_contrast.ipynb index eefc5c29..838bb763 100644 --- a/docs/multi_contrast.ipynb +++ b/docs/multi_contrast.ipynb @@ -9,8 +9,15 @@ "\n", "In the use of neutron reflectometry, it is common to use multiple isotopic contrasts of experimental data to analyse a system in a constrained fashion. \n", "That is to say, that we have data from multiple different species (where isotopic substitution has been used to produce data with different scattering length density) that shar ethe same structure. \n", - "In this tutorial we will look at how `EasyReflectometry` can be used to fit multiple contrasts of data from a [surfactant monolayer](./monolayer.html) system, if you haven't looked at the tutorial for a single contrast of surfactant monolayer data it is suggested that you as this tutorial will build on it.\n", - "First, as always, we import the relevant packages and print the version numbers." + "In this tutorial we will look at how `EasyReflectometry` can be used to fit multiple contrasts of data from a [surfactant monolayer](./monolayer.html) system, if you haven't looked at the tutorial for a single contrast of surfactant monolayer data it is suggested that you as this tutorial will build on it." + ] + }, + { + "cell_type": "markdown", + "id": "9e2929d2", + "metadata": {}, + "source": [ + "First configure matplotlib to place figures in notebook and import needed modules" ] }, { @@ -20,6 +27,8 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import EasyReflectometry\n", "import refnx\n", "from EasyReflectometry.data import load\n", @@ -439,7 +448,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/docs/repeating.ipynb b/docs/repeating.ipynb index 49642573..a1c97b34 100644 --- a/docs/repeating.ipynb +++ b/docs/repeating.ipynb @@ -16,6 +16,14 @@ "Before performing analysis, we should import the packages that we need." ] }, + { + "cell_type": "markdown", + "id": "f5d0bd58", + "metadata": {}, + "source": [ + "First configure matplotlib to place figures in notebook and import needed modules" + ] + }, { "cell_type": "code", "execution_count": null, @@ -23,6 +31,8 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import numpy as np\n", "import scipp as sc\n", "import EasyReflectometry\n", diff --git a/docs/simple_fitting.ipynb b/docs/simple_fitting.ipynb index be88bea8..5b739116 100644 --- a/docs/simple_fitting.ipynb +++ b/docs/simple_fitting.ipynb @@ -12,6 +12,14 @@ "Before we start on any analysis, we will import the necessary packages and functions." ] }, + { + "cell_type": "markdown", + "id": "d0fea80b", + "metadata": {}, + "source": [ + "First configure matplotlib to place figures in notebook and import needed modules" + ] + }, { "cell_type": "code", "execution_count": null, @@ -19,6 +27,8 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import EasyReflectometry\n", "import refnx\n", "from EasyReflectometry.data import load\n", diff --git a/docs/solvation.ipynb b/docs/solvation.ipynb index 3919db99..1c3961b4 100644 --- a/docs/solvation.ipynb +++ b/docs/solvation.ipynb @@ -15,6 +15,14 @@ "Here, we will show how to use the `MaterialMixture` [type](./material_library.html#materialmixture) to perform this analysis. " ] }, + { + "cell_type": "markdown", + "id": "f404875e", + "metadata": {}, + "source": [ + "First configure matplotlib to place figures in notebook and import needed modules" + ] + }, { "cell_type": "code", "execution_count": null, @@ -22,6 +30,8 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import numpy as np\n", "import scipp as sc\n", "import EasyReflectometry\n", @@ -333,7 +343,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/pyproject.toml b/pyproject.toml index 4bcc182b..9381764e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,20 +34,21 @@ dependencies = [ [project.optional-dependencies] dev = [ - "pytest>=5.2", - "pytest-cov>=3.0.0", "codecov>=2.1.11", - "yapf>=0.31.0", - "toml>=0.10", - "jupyter>=1.0.0", - "flake8>=6.0.0", - "jupyterlab", "coverage", "coveralls", + "flake8>=6.0.0", "ipykernel", + "jupyter>=1.0.0", + "jupyterlab", "nbsphinx", + "plopp", + "pytest>=5.2", + "pytest-cov>=3.0.0", "sphinx_book_theme", - "sphinx_autodoc_typehints" + "sphinx_autodoc_typehints", + "toml>=0.10", + "yapf>=0.31.0", ] [project.urls]