{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Plots: MassProfileCentreScatter\n", "===============================\n", "\n", "This example illustrates how to customize the mass profile centres plotted over data.\n", "\n", "__Start Here Notebook__\n", "\n", "If any code in this script is unclear, refer to the `plot/start_here.ipynb` notebook." ] }, { "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", "import autolens as al\n", "import autolens.plot as aplt" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "This means the centre of every `MassProfile` of every `Galaxy` in a plot are plotted on the figure. \n", "A `Tracer` object is a good example of an object with many `MassProfiles`, so lets make one with three." ] }, { "cell_type": "code", "metadata": {}, "source": [ "lens_galaxy_0 = al.Galaxy(\n", " redshift=0.25,\n", " mass=al.mp.Isothermal(centre=(0.0, 1.0), einstein_radius=0.8, ell_comps=(0.2, 0.2)),\n", ")\n", "\n", "lens_galaxy_1 = al.Galaxy(\n", " redshift=0.5,\n", " mass=al.mp.Isothermal(\n", " centre=(0.0, -1.0), einstein_radius=0.8, ell_comps=(0.2, 0.2)\n", " ),\n", ")\n", "\n", "source_galaxy = al.Galaxy(\n", " redshift=1.0,\n", " bulge=al.lp.SersicSph(\n", " centre=(0.1, 0.1), intensity=0.3, effective_radius=1.0, sersic_index=2.5\n", " ),\n", ")\n", "\n", "tracer = al.Tracer(galaxies=[lens_galaxy_0, lens_galaxy_1, source_galaxy])" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "We also need the `Grid2D` that we can use to make plots of the `Tracer`'s properties." ] }, { "cell_type": "code", "metadata": {}, "source": [ "grid = al.Grid2D.uniform(shape_native=(100, 100), pixel_scales=0.05)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "The mass profile centres are an internal property of the `Tracer`, so we can plot them via an `Include2D` object." ] }, { "cell_type": "code", "metadata": {}, "source": [ "include = aplt.Include2D(\n", " light_profile_centres=False,\n", " mass_profile_centres=True,\n", " tangential_critical_curves=False,\n", " radial_critical_curves=False,\n", " tangential_caustics=False,\n", " radial_caustics=False,\n", ")\n", "tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid, include_2d=include)\n", "tracer_plotter.figures_2d(image=True)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "The appearance of the mass profile centres are customized using a `MassProfileCentresScatter` object.\n", "\n", "To plot the mass profile centres this object wraps the following matplotlib method:\n", "\n", " https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.pyplot.scatter.html" ] }, { "cell_type": "code", "metadata": {}, "source": [ "mass_profile_centres_scatter = aplt.MassProfileCentresScatter(marker=\"o\", c=\"r\", s=150)\n", "mat_plot = aplt.MatPlot2D(mass_profile_centres_scatter=mass_profile_centres_scatter)\n", "tracer_plotter = aplt.TracerPlotter(\n", " tracer=tracer, grid=grid, include_2d=include, mat_plot_2d=mat_plot\n", ")\n", "tracer_plotter.figures_2d(image=True)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "By specifying two colors to the `MassProfileCentresScatter` object the mass profile centres of each plane\n", "are plotted in different colors." ] }, { "cell_type": "code", "metadata": {}, "source": [ "mass_profile_centres_scatter = aplt.MassProfileCentresScatter(c=[\"r\", \"w\"], s=150)\n", "\n", "mat_plot = aplt.MatPlot2D(mass_profile_centres_scatter=mass_profile_centres_scatter)\n", "\n", "tracer_plotter = aplt.TracerPlotter(\n", " tracer=tracer, grid=grid, include_2d=include, mat_plot_2d=mat_plot\n", ")\n", "tracer_plotter.figures_2d(image=True)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the mass profile centres manually, we can pass them into a` Visuals2D` object. This is useful for plotting \n", "the centres on figures where they are not an internal property, like an `Array2D`." ] }, { "cell_type": "code", "metadata": {}, "source": [ "mass_profile_centres = tracer.extract_attribute(\n", " cls=al.mp.MassProfile, attr_name=\"centre\"\n", ")\n", "visuals = aplt.Visuals2D(mass_profile_centres=mass_profile_centres)\n", "image = tracer.image_2d_from(grid=grid)\n", "\n", "array_plotter = aplt.Array2DPlotter(\n", " array=image, mat_plot_2d=mat_plot, visuals_2d=visuals\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 }