{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Plots: PositionsScatter\n", "=======================\n", "\n", "This example illustrates how to customize the positions of plotted data.\n", "\n", "Although a positions is a 2D array of values, it is actually plotted as a `Grid2D` of (y,x) coordinates corresponding to the\n", "centre of every pixel at the edge of the positions. The positions is therefore plotted using the `GridScatter` object described\n", "in `autolens_workspace.plot.mat_wramat_plot.wrap.base`.\n", "\n", "The `PositionsScatter` object serves the purpose is allowing us to uniquely customize the appearance of any positions\n", "on a plot." ] }, { "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": [ "First, lets load an example Hubble Space Telescope image of a real strong lens as an `Array2D`." ] }, { "cell_type": "code", "metadata": {}, "source": [ "dataset_path = path.join(\"dataset\", \"slacs\", \"slacs1430+4105\")\n", "data_path = path.join(dataset_path, \"data.fits\")\n", "data = al.Array2D.from_fits(file_path=data_path, hdu=0, pixel_scales=0.03)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will also need a positions to plot on the figure, we'll set these up as a `Grid2DIrregular` of 2D (y,x) coordinates." ] }, { "cell_type": "code", "metadata": {}, "source": [ "positions = al.Grid2DIrregular(values=[(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)])" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the positions manually, we can pass it into a` Visuals2D` object." ] }, { "cell_type": "code", "metadata": {}, "source": [ "visuals = aplt.Visuals2D(positions=positions)\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": [ "The appearance of the positions is customized using a `Scatter` object.\n", "\n", "To plot the positions 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": [ "positions_scatter = aplt.PositionsScatter(marker=\"o\", c=\"r\", s=50)\n", "\n", "mat_plot = aplt.MatPlot2D(positions_scatter=positions_scatter)\n", "\n", "array_plotter = aplt.Array2DPlotter(\n", " array=data, 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 }