{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Plots: VectorYXQuiver\n", "========================\n", "\n", "This example illustrates how to plot and customize vector fields in PyAutoLens figures and subplots.\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", "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 need a `VectorField` to plot over the image. We make a simple example of a vector field below." ] }, { "cell_type": "code", "metadata": {}, "source": [ "vectors = al.VectorYX2DIrregular(\n", " values=[(1.0, 2.0), (2.0, 1.0)], grid=[(-1.0, 0.0), (-2.0, 0.0)]\n", ")" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the vector field manually, we can pass it into a` Visuals2D` object." ] }, { "cell_type": "code", "metadata": {}, "source": [ "visuals = aplt.Visuals2D(vectors=vectors)\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": [ "We can customize the appearance of the vectors using the `VectorYXQuiver` matplotlib wrapper object which wraps \n", "the following method(s):\n", "\n", " https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.quiver.html" ] }, { "cell_type": "code", "metadata": {}, "source": [ "quiver = aplt.VectorYXQuiver(\n", " headlength=1,\n", " pivot=\"tail\",\n", " color=\"w\",\n", " linewidth=10,\n", " units=\"width\",\n", " angles=\"uv\",\n", " scale=None,\n", " width=0.5,\n", " headwidth=3,\n", " alpha=0.5,\n", ")\n", "\n", "mat_plot = aplt.MatPlot2D(vector_yx_quiver=quiver)\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 }