{ "cells": [ { "cell_type": "markdown", "id": "adult-childhood", "metadata": {}, "source": [ "# Plotting\n", "McStasScript includes a [plotting](../_autosummary/mcstasscript.interface.plotter.rst) module meant for plotting McStasScript data objects. \n", "\n", "## Example instrument\n", "First an example instrument is constructed to provide some data for plotting examples." ] }, { "cell_type": "code", "execution_count": null, "id": "perfect-hours", "metadata": { "tags": [ "hide-input" ] }, "outputs": [], "source": [ "import mcstasscript as ms\n", "\n", "instrument = ms.McStas_instr(\"data_example\")\n", "\n", "source = instrument.add_component(\"source\", \"Source_simple\")\n", "source.set_parameters(xwidth=0.05, yheight=0.03, dlambda=0.02,\n", " dist=5, focus_xw=0.015, focus_yh=0.03)\n", "source.lambda0 = instrument.add_parameter(\"wavelength\", value=2.0)\n", "\n", "sample = instrument.add_component(\"sample\", \"PowderN\")\n", "sample.set_parameters(radius=source.focus_xw, yheight=0.8*source.focus_yh,\n", " reflections='\"Na2Ca3Al2F14.laz\"')\n", "sample.set_AT(source.dist, RELATIVE=source)\n", "\n", "banana = instrument.add_component(\"banana\", \"Monitor_nD\", RELATIVE=sample)\n", "banana.set_parameters(xwidth=1.5, yheight=0.4, restore_neutron=1, filename='\"banana.dat\"')\n", "banana.options = '\"theta limits=[5 175] bins=250, banana\"'\n", "\n", "mon = instrument.add_component(\"PSD\", \"PSD_monitor\")\n", "mon.set_AT(0.1, RELATIVE=sample)\n", "mon.set_parameters(nx=100, ny=100, filename='\"psd.dat\"',\n", " xwidth=5*sample.radius, yheight=2*sample.yheight, restore_neutron=1)" ] }, { "cell_type": "markdown", "id": "catholic-distribution", "metadata": {}, "source": [ "### Performing the simulation\n", "Here the simulation is performed to provide the example data." ] }, { "cell_type": "code", "execution_count": null, "id": "general-chance", "metadata": { "scrolled": true, "tags": [ "scroll-output", "hide-output" ] }, "outputs": [], "source": [ "instrument.settings(ncount=1E6, output_path=\"plotting_example\")\n", "instrument.set_parameters(wavelength=1.5)\n", "data = instrument.backengine()" ] }, { "cell_type": "code", "execution_count": null, "id": "retired-tiffany", "metadata": {}, "outputs": [], "source": [ "print(data)" ] }, { "cell_type": "markdown", "id": "alpine-arnold", "metadata": {}, "source": [ "## make_plot and make_sub_plot\n", "The first available plotter is [*make_plot*](../_autosummary/mcstasscript.interface.plotter.make_plot.rst), it makes a single figure for each [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst) set given in the input." ] }, { "cell_type": "code", "execution_count": null, "id": "literary-costs", "metadata": {}, "outputs": [], "source": [ "ms.make_plot(data)" ] }, { "cell_type": "markdown", "id": "norwegian-growth", "metadata": {}, "source": [ "The second available plotter is [*make_sub_plot*](../_autosummary/mcstasscript.interface.plotter.make_sub_plot.rst), it makes a single figure that includes plot of all given [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst) as subplots. This works best with between 1 and 9 monitors, as more tend to become difficult to read." ] }, { "cell_type": "code", "execution_count": null, "id": "pretty-transcription", "metadata": {}, "outputs": [], "source": [ "ms.make_sub_plot(data)" ] }, { "cell_type": "markdown", "id": "behind-pleasure", "metadata": {}, "source": [ "## Customizing plots\n", "As described in the data section of the documentation, the [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst) objects contain preferences on how they should be plotted. The same keywords can however be given to the plotters to override these preferences. When plotting a list of [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst) objects, a list can be given for each keyword." ] }, { "cell_type": "code", "execution_count": null, "id": "natural-transition", "metadata": {}, "outputs": [], "source": [ "ms.make_sub_plot(data, log=[False, True], fontsize=15)" ] }, { "cell_type": "markdown", "id": "backed-mirror", "metadata": {}, "source": [ "### Available keywords\n", "The keywords available to customize plotting are the same as can be set for *plot_options* in [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst). There are however a few additional keywords for controlling figure size and fontsize.\n", "\n", "| Keyword argument | Type | Default | Description |\n", "| --- | --- | --- | --- |\n", "| figsize | tuple | (13, 7) | Tuple describing figure size |\n", "| fontsize | int | 11 | Fontsize to use in plotting |\n", "| log | bool | False | Logarithmic axis for y in 1D or z in 2D |\n", "| orders_of_mag | float | 300 | Maximum orders of magnitude to plot in 2D |\n", "| colormap | str | \"jet\" | Matplotlib colormap to use |\n", "| show_colorbar | bool | True | Show the colorbar |\n", "| x_axis_multiplier | float | 1 | Multiplier for x axis data |\n", "| y_axis_multiplier | float | 1 | Multiplier for y axis data |\n", "| cut_min | float | 0 | Unitless lower limit normalized to data range |\n", "| cut_max | float | 1 | Unitless upper limit normalized to data range |\n", "| left_lim | float | | Lower limit to plot range of x axis |\n", "| right_lim | float | | Upper limit to plot range of x axis|\n", "| bottom_lim | float | | Lower limit to plot range of y axis|\n", "| top_lim | float | | Upper limit to plot range of y axis|" ] }, { "cell_type": "code", "execution_count": null, "id": "declared-welsh", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "dedicated-addiction", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Tags", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" }, "metadata": { "execution": { "timeout": 100 } } }, "nbformat": 4, "nbformat_minor": 5 }