{ "cells": [ { "cell_type": "markdown", "metadata": { "tags": [ "notebook-header" ] }, "source": [ "[![GitHub issues by-label](https://img.shields.io/github/issues-raw/pfebrer/sisl/GeometryPlot?style=for-the-badge)](https://github.com/pfebrer/sisl/labels/GeometryPlot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " \n", " \n", "GeometryPlot\n", "=========" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sisl\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First of all, we will create a geometry to work with" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geom = sisl.geom.graphene_nanoribbon(9)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`GeometryPlot` allows you to quickly visualize a geometry. You can create a `GeometryPlot` out of a geometry very easily:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# GeometryPlot is the default plot of a geometry, so one can just do\n", "plot = geom.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's see what we got:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting in 3D, 2D and 1D\n", "\n", "The 3D view is great, but for big geometries it can take some time to render. If we have a 2d material, a 2D view might be more practical instead. We can get it by specifying the axes that we want:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=\"xy\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next section goes more in depth on what the `axes` setting accepts. The important part for now is that asking for two axes gets you a 2D representation. Samewise, asking for 1 axis gets you a 1D representation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(\n", " axes=\"x\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice how asking for a 1D representation leaves the Y axis of the plot at your disposal. You can control the values in the second axis using the `dataaxis_1d` setting.\n", "\n", "It can be an array that **explicitly sets the values**:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or a function that **accepts the projected coordinates and returns the values**." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(dataaxis_1d=np.sin)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Asking for three axes would bring us back to the 3D representation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=\"xyz\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Specifying the axes\n", "----------\n", "\n", "There are many ways in which you may want to display the coordinates of your geometry. The most common one is to display the cartesian coordinates. You indicate that you want cartesian coordinates by passing `(+-){\"x\", \"y\", \"z\"}`. You can pass them as a list: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=[\"x\", \"y\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But it is usually more convenient to pass them as a multicharacter string:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=\"xy\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that you can order axes in any way you want. The first one will go to the X axis of the plot, and the second to the Y axis:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=\"yx\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You are not limited to cartesian coordinates though. Passing `(+-){\"a\", \"b\", \"c\"}` will display the fractional coordinates:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=\"ab\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And you can also pass an **arbitrary direction** as an axis: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=[[1, 1, 0], [1, -1, 0]])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this case, we have projected the coordinates into the `[1,1,0]` and `[1, -1, 0]` directions. Notice that the modulus of the vector is important for the scaling. See for example what happens when we scale the second vector by a factor of two:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=[[1, 1, 0], [2, -2, 0]])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, you can even mix the different possibilities!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.update_inputs(axes=[\"x\", [1, 1, 0]])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To summarize the different possibilities:\n", "\n", "- `(+-){\"x\", \"y\", \"z\"}`: The **cartesian coordinates** are displayed.\n", "- `(+-){\"a\", \"b\", \"c\"}`: The **fractional coordinates** are displayed. Same for {0,1,2}.\n", "- `np.array of shape (3, )`: The coordinates are **projected into that direction**. If two directions are passed, the coordinates are not projected to each axis separately. The displayed coordinates are then the coefficients of the linear combination to get that point (or the projection of that point into the plane formed by the two axes).\n", "\n", "