{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Plots: Start Here\n", "=================\n", "\n", "This example illustrates the basic API for plotting." ] }, { "cell_type": "code", "metadata": {}, "source": [ "%matplotlib inline\n", "from pyprojroot import here\n", "workspace_path = str(here())\n", "%cd $workspace_path\n", "print(f\"Working Directory has been set to `{workspace_path}`\")\n", "\n", "from os import path\n", "import autolens as al\n", "import autolens.plot as aplt" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Dataset__\n", "\n", "First, lets load an example image of of a strong lens as an `Array2D`." ] }, { "cell_type": "code", "metadata": {}, "source": [ "dataset_name = \"simple__no_lens_light\"\n", "dataset_path = path.join(\"dataset\", \"imaging\", dataset_name)\n", "data_path = path.join(dataset_path, \"data.fits\")\n", "data = al.Array2D.from_fits(file_path=data_path, hdu=0, pixel_scales=0.1)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Figures__\n", "\n", "We now pass the array to an `Array2DPlotter` and call the `figure` method.\n", "\n", "The `autolens.workspace.*.plot.plotters` illustrates every `Plotter` object, for \n", "example `ImagingPlotter`, `LightProfilePlotter`, etc." ] }, { "cell_type": "code", "metadata": {}, "source": [ "array_plotter = aplt.Array2DPlotter(array=data)\n", "array_plotter.figure_2d()" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Plot Customization via MatPlot__\n", "\n", "You can customize a number of matplotlib setup options using a `MatPlot` object, which \n", "wraps the `matplotlib` methods used to display the image.\n", "\n", "(For example, the `Figure` class wraps the `matplotlib` method `plt.figure()`, whereas the `YTicks` class wraps\n", "`plt.yticks`).\n", "\n", "The `autolens.workspace.*.plot.mat_wrap` illustrates every `MatPlot` object, for \n", "example `Figure`, `YTicks`, etc." ] }, { "cell_type": "code", "metadata": {}, "source": [ "mat_plot = aplt.MatPlot2D(\n", " figure=aplt.Figure(figsize=(7, 7)),\n", " yticks=aplt.YTicks(fontsize=8),\n", " xticks=aplt.XTicks(fontsize=8),\n", " title=aplt.Title(fontsize=12),\n", " ylabel=aplt.YLabel(fontsize=6),\n", " xlabel=aplt.XLabel(fontsize=6),\n", ")\n", "\n", "array_plotter = aplt.Array2DPlotter(array=data, mat_plot_2d=mat_plot)\n", "array_plotter.figure_2d()" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Configs__\n", "\n", "All matplotlib options can be customized via the config files, such that those values are used every time.\n", "\n", "Checkout the `mat_wrap.yaml`, `mat_wrap_1d.yaml` and `mat_wrap_2d.yaml` files \n", "in `autolens_workspace/config/visualize/mat_wrap`.\n", "\n", "All default matplotlib values are here. There are a lot of entries, so lets focus on whats important for displaying \n", "figures:\n", "\n", " - mat_wrap.yaml -> Figure -> figure: -> figsize\n", " - mat_wrap.yaml -> YLabel -> figure: -> fontsize\n", " - mat_wrap.yaml -> XLabel -> figure: -> fontsize\n", " - mat_wrap.yaml -> TickParams -> figure: -> labelsize\n", " - mat_wrap.yaml -> YTicks -> figure: -> labelsize\n", " - mat_wrap.yaml -> XTicks -> figure: -> labelsize\n", "\n", "__Subplots__\n", "\n", "In addition to plotting individual `figures`, **PyAutoLens** can also plot `subplots` which are again customized via\n", "the `mat_plot` objects.\n", "\n", "__Visuals__\n", "\n", "Visuals can be added to any figure, using standard quantities.\n", "\n", "For example, we can plot a mask on the image above using a `Visuals2D` object.\n", "\n", "The `autolens.workspace.*.plot.visuals_2d` illustrates every `Visuals` object, for \n", "example `MaskScatter`, `LightProfileCentreScatter`, etc." ] }, { "cell_type": "code", "metadata": {}, "source": [ "mask = al.Mask2D.circular_annular(\n", " shape_native=data.shape_native,\n", " pixel_scales=data.pixel_scales,\n", " inner_radius=0.3,\n", " outer_radius=3.0,\n", ")\n", "\n", "visuals = aplt.Visuals2D(mask=mask)\n", "\n", "array_plotter = aplt.Array2DPlotter(array=data, visuals_2d=visuals)\n", "array_plotter.figure_2d()" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Searches__\n", "\n", "Model-fits using a non-linear search (e.g. Nautilus, Emcee) produce search-specific visualization.\n", "\n", "The `autolens.workspace.*.plot.search` illustrates how to perform this visualization for every search (e.g.\n", "`NestPlotter`.\n", "\n", "__Adding Plotter Objects Together__\n", "\n", "The `MatPlot` objects can be added together. \n", "\n", "This is useful when we want to perform multiple visualizations which share the same base settings, but have\n", "individually tailored settings:" ] }, { "cell_type": "code", "metadata": {}, "source": [ "mat_plot_base = aplt.MatPlot2D(\n", " yticks=aplt.YTicks(fontsize=18),\n", " xticks=aplt.XTicks(fontsize=18),\n", " ylabel=aplt.YLabel(ylabel=\"\"),\n", " xlabel=aplt.XLabel(xlabel=\"\"),\n", ")\n", "\n", "mat_plot = aplt.MatPlot2D(\n", " title=aplt.Title(label=\"Example Figure 1\"),\n", ")\n", "\n", "mat_plot = mat_plot + mat_plot_base\n", "\n", "array_plotter = aplt.Array2DPlotter(array=data, mat_plot_2d=mat_plot)\n", "array_plotter.figure_2d()\n", "\n", "mat_plot = aplt.MatPlot2D(\n", " title=aplt.Title(label=\"Example Figure 2\"),\n", ")\n", "\n", "mat_plot = mat_plot + mat_plot_base\n", "\n", "array_plotter = aplt.Array2DPlotter(array=data, mat_plot_2d=mat_plot)\n", "array_plotter.figure_2d()\n", "\n", "mat_plot = mat_plot + mat_plot_base\n" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Visuals` objects can also be added together." ] }, { "cell_type": "code", "metadata": {}, "source": [ "light_profile_centres = al.Grid2DIrregular(values=[(1.0, 0.0), (0.0, 1.0)])\n", "\n", "visuals_2d_0 = aplt.Visuals2D(mask=mask)\n", "visuals_2d_1 = aplt.Visuals2D(light_profile_centres=light_profile_centres)\n", "\n", "visuals = visuals_2d_0 + visuals_2d_1\n", "\n", "array_plotter = aplt.Array2DPlotter(\n", " array=data, visuals_2d=visuals, mat_plot_2d=aplt.MatPlot2D()\n", ")\n", "array_plotter.figure_2d()" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finish." ] }, { "cell_type": "code", "metadata": {}, "source": [], "outputs": [], "execution_count": null } ], "metadata": { "anaconda-cloud": {}, "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.6.1" } }, "nbformat": 4, "nbformat_minor": 4 }