├── .github └── workflows │ └── repo2docker.yml ├── LICENSE ├── Project.toml ├── README.md ├── bash-demo.ipynb ├── environment.yml ├── julia-demo.ipynb ├── landing-page.ipynb ├── postBuild ├── python-demo-google-colab.ipynb └── python-demo.ipynb /.github/workflows/repo2docker.yml: -------------------------------------------------------------------------------- 1 | # This workflow runs repo2docker to check if this repository is a valid binder repo 2 | name: Validator 3 | 4 | on: 5 | pull_request: 6 | branches: [ main ] 7 | 8 | jobs: 9 | repo2docker: 10 | name: Run repo2docker 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v2 16 | 17 | - name: Setup Miniconda 18 | uses: conda-incubator/setup-miniconda@v2 19 | with: 20 | channels: conda-forge 21 | 22 | - name: Install dependencies 23 | shell: bash -l {0} 24 | run: conda install jupyter-repo2docker 25 | 26 | - name: Show installed package 27 | shell: bash -l {0} 28 | run: conda list 29 | 30 | - name: Run repo2docker 31 | shell: bash -l {0} 32 | run: jupyter-repo2docker --no-run --ref ${{ github.event.pull_request.head.sha }} https://github.com/${{ github.event.pull_request.head.repo.full_name }} 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020-2024, The GMT Team 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Project.toml: -------------------------------------------------------------------------------- 1 | [deps] 2 | GMT = "5752ebe1-31b9-557e-87aa-f909b540aa54" 3 | IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" 4 | 5 | [compat] 6 | julia = "1.10" 7 | GMT = "1" 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Try GMT, PyGMT, and GMT.jl online 2 | 3 | This is an online Jupyter lab environment with the latest 4 | [GMT](https://www.generic-mapping-tools.org/), 5 | [PyGMT](https://www.pygmt.org/), 6 | and [GMT.jl](https://www.generic-mapping-tools.org/GMT.jl/) 7 | versions installed. 8 | 9 | Run it online by clicking on one of the badges below: 10 | 11 | - [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/GenericMappingTools/try-gmt/main?urlpath=lab/tree/landing-page.ipynb) hosted at https://mybinder.org/ 12 | - [![Binder](https://mybinder.org/badge_logo.svg)](https://ovh.mybinder.org/v2/gh/GenericMappingTools/try-gmt/main?urlpath=lab/tree/landing-page.ipynb) hosted at https://ovh.mybinder.org/ 13 | - [![Binder](https://mybinder.org/badge_logo.svg)](https://notebooks.gesis.org/binder/v2/gh/GenericMappingTools/try-gmt/main?urlpath=lab/tree/landing-page.ipynb) hosted at https://notebooks.gesis.org/binder/ 14 | - [![Binder](https://mybinder.org/badge_logo.svg)](https://binder.curvenote.dev/v2/gh/GenericMappingTools/try-gmt/main?urlpath=lab/tree/landing-page.ipynb) hosted at https://binder.curvenote.dev/ 15 | - [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/GenericMappingTools/try-gmt/blob/main/landing-page.ipynb) hosted by [Google Colab](https://colab.research.google.com/) (Need to log in to your Google account). 16 | 17 | ## Installed packages 18 | 19 | - **GMT**: 6.5.0 20 | - **Julia**: 1.10 21 | - **GMT.jl**: 1.x 22 | - **Python**: 3.13 23 | - **PyGMT**: 0.15.0 24 | - **Geopandas**: 1.0.1 25 | 26 | ## Reference 27 | 28 | - [Binder Documentation](https://mybinder.readthedocs.io/en/latest/index.html) 29 | 30 | ## License 31 | 32 | You can redistribute and/or modify this code under the terms of the **BSD 3-clause License**. 33 | A copy of this license is provided in `LICENSE`. 34 | -------------------------------------------------------------------------------- /bash-demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Run GMT in bash" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "This Jupyter lab environment has the latest GMT installed. You can run any GMT commands with no extra install required.\n", 15 | "\n", 16 | "**NOTE:** Any changes will be lost when the Jupyter lab is closed. Select \"File\"->\"Download\" to save notebooks to your computer." 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "To execute the code cells, select it and type `Shift + Enter` or click on the \"Run\" ► button in the menu bar. Cells that start with `%%bash` run their code through the bash shell (use them to execute GMT commands). Other cells contain Python code or Markdown text (like this one). " 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "We'll use the `IPython.display.Image` class to display in the notebook the PNG figures that you generate on the `%%bash` cells.\n", 31 | "\n", 32 | "Start by executing the cell below (`shift+enter`) to import the class." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "# Load the class first. This only needs to be run once\n", 42 | "from IPython.display import Image" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Check installed GMT version\n", 50 | "\n", 51 | "Before starting, let's first check the version of the installed GMT." 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "%%bash\n", 61 | "gmt --version" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Example 1" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "%%bash\n", 78 | "gmt begin globe png\n", 79 | " gmt coast -Rg -JH15c -Bafg -Glightbrown -Slightblue\n", 80 | "gmt end" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "Image('globe.png', width=500)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "## Example 2" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "%%bash\n", 106 | "gmt begin hotspots png\n", 107 | " gmt grdimage @earth_relief_20m -JG200/30/12c -Bafg -Cgeo -I+d\n", 108 | " gmt coast -Dc -W -A1000\n", 109 | " gmt plot @hotspots.txt -Sc0.2c -Gred\n", 110 | "gmt end" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "Image('hotspots.png', width=500)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "## Experiment for yourself" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "Try running different things in the cells below or edit and rerun the cells above." 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "%%bash\n", 143 | "gmt begin XXX png\n", 144 | " # Any GMT commands here\n", 145 | "gmt end" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "Image('XXX.png', width=500)" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "%%bash\n", 164 | "gmt begin XXX png\n", 165 | " # Any GMT commands here\n", 166 | "gmt end" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "Image('XXX.png', width=500)" 176 | ] 177 | } 178 | ], 179 | "metadata": { 180 | "kernelspec": { 181 | "display_name": "Python 3", 182 | "language": "python", 183 | "name": "python3" 184 | }, 185 | "language_info": { 186 | "codemirror_mode": { 187 | "name": "ipython", 188 | "version": 3 189 | }, 190 | "file_extension": ".py", 191 | "mimetype": "text/x-python", 192 | "name": "python", 193 | "nbconvert_exporter": "python", 194 | "pygments_lexer": "ipython3", 195 | "version": "3.8.3" 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 4 200 | } 201 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: try-gmt 2 | channels: 3 | - conda-forge 4 | - nodefaults 5 | dependencies: 6 | - python=3.13 7 | - gmt=6.5.0 8 | - pygmt=0.15.0 9 | - jupyterlab=4.3.6 10 | - jupyter-offlinenotebook=0.3.1 11 | # Optional dependencies 12 | - geopandas=1.0.1 13 | -------------------------------------------------------------------------------- /julia-demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Try GMT.jl online" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "This Jupyter lab environment has the latest GMT.jl installed. You can try GMT.jl with no extra install required." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "**NOTE:** Any changes will be lost when the Jupyter lab is closed. Select \"File\"->\"Download\" to save notebooks to your computer." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "To execute the code cells, select it and type `Shift + Enter` or click on the \"Run\" ► button in the menu bar. \n", 29 | "\n", 30 | "For tutorials and more examples, visit the official website: https://www.generic-mapping-tools.org/GMT.jl" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Loading the GMT.jl package" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "# Load the GMT.jl package. This only needs to be run once\n", 47 | "using GMT" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "## Example 1" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "Here we plot the global coastlines using the Hammer projection. The `show=true` is needed to show the image in the notebook." 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "coast(region=:g, proj=:Hammer, frame=:g, land=:black, ocean=:cornsilk, show=true)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "## Example 2" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "An image is usually made up with multiple layers of data. Here we are going to plot hotspot locations on a global map with earth relief and coastlines. \n", 85 | "\n", 86 | "- The first command use the `basemap` function to define the projection, region and plot the basemap. \n", 87 | "- The remaining commands use the `!` variation of the functions, which means that we are appending to a previous plot. \n", 88 | "- The last command uses the `show=true` because we are done with this figure. " 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "basemap(region=:g, proj=(name=:Ortho, center=(220,30)), figsize=8, frame=:g)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "grdimage!(\"@earth_relief_20m\", cmap=:geo, shade=true)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "coast!(res=:crude, shore=true, area=1000)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "plot!(\"@hotspots.txt\", marker=:circle, size=\"0.2c\", markerfacecolor=:red, show=true)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": {}, 130 | "source": [ 131 | "## Experiment for yourself" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "Try running different things in the cells below or edit and rerun the cells above." 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [] 147 | } 148 | ], 149 | "metadata": { 150 | "kernelspec": { 151 | "display_name": "Julia 1.3.1", 152 | "language": "julia", 153 | "name": "julia-1.3" 154 | }, 155 | "language_info": { 156 | "file_extension": ".jl", 157 | "mimetype": "application/julia", 158 | "name": "julia", 159 | "version": "1.3.1" 160 | } 161 | }, 162 | "nbformat": 4, 163 | "nbformat_minor": 4 164 | } 165 | -------------------------------------------------------------------------------- /landing-page.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Welcome to the Generic Mapping Tools!" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "\"GMT\n", 15 | "\n", 16 | "GMT is an open-source collection of command-line tools for manipulating geographic and Cartesian data sets (including filtering, trend fitting, gridding, projecting, etc.) and producing high-quality illustrations ranging from simple x–y plots via contour maps to artificially illuminated surfaces and 3D perspective views. It supports many map projections and transformations and includes supporting data such as coastlines, rivers, and political boundaries and optionally country polygons." 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Try GMT, PyGMT, and GMT.jl online" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "This Jupyter lab environment has the latest GMT, PyGMT, and GMT.jl installed. \n", 31 | "\n", 32 | "You can try them **all in one place** with no extra install required. \n", 33 | "\n", 34 | "- [Run GMT command in bash](./bash-demo.ipynb)\n", 35 | "- [Try PyGMT online](./python-demo.ipynb)\n", 36 | "- [Try PyGMT on Google Colab](./python-demo-google-colab.ipynb)\n", 37 | "- [Try GMT.jl online](./julia-demo.ipynb)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Learning Resources" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "- GMT website: https://www.generic-mapping-tools.org/\n", 52 | "- GMT documentation: https://docs.generic-mapping-tools.org/\n", 53 | "- GMT Community Forum: https://forum.generic-mapping-tools.org/\n", 54 | "- PyGMT website: https://www.pygmt.org/\n", 55 | "- GMT.jl website: https://www.generic-mapping-tools.org/GMT.jl/\n" 56 | ] 57 | } 58 | ], 59 | "metadata": { 60 | "kernelspec": { 61 | "display_name": "Python 3", 62 | "language": "python", 63 | "name": "python3" 64 | }, 65 | "language_info": { 66 | "codemirror_mode": { 67 | "name": "ipython", 68 | "version": 3 69 | }, 70 | "file_extension": ".py", 71 | "mimetype": "text/x-python", 72 | "name": "python", 73 | "nbconvert_exporter": "python", 74 | "pygments_lexer": "ipython3", 75 | "version": "3.7.6" 76 | } 77 | }, 78 | "nbformat": 4, 79 | "nbformat_minor": 4 80 | } 81 | -------------------------------------------------------------------------------- /postBuild: -------------------------------------------------------------------------------- 1 | # Notes: 2 | # 1. Have to run the command multiple times to avoid any potential network connection issues 3 | 4 | for i in $(seq 1 3); do 5 | for res in 01d 30m 20m 15m 10m 06m; do 6 | gmt which -Ga @earth_relief_${res}_p 7 | done 8 | done 9 | gmt which -Ga @hotspots.txt 10 | -------------------------------------------------------------------------------- /python-demo-google-colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Try PyGMT on Google Colab" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "This Jupyter Notebook shows how to install and use PyGMT on Google Colab." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "**NOTE:** Any changes will be lost when the Jupyter lab is closed. Select \"File\"->\"Download\" to save notebooks to your computer." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "To execute the code cells, select it and type `Shift + Enter` or click on the \"Run\" ► button in the menu bar. \n", 29 | "\n", 30 | "For tutorials and more examples, visit the official website: https://www.pygmt.org" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": { 36 | "tags": [] 37 | }, 38 | "source": [ 39 | "## Install PyGMT and its dependencies on Google Colab\n", 40 | "\n", 41 | "**Google Colab** doesn't have PyGMT and its dependencies installed. We need to follow the instructions below to install them.\n", 42 | "\n", 43 | "First, we need to install conda on Google Colab. The installation process is greatly simplified using the [condacolab](https://github.com/conda-incubator/condacolab) package.\n", 44 | "\n", 45 | "*After condacolab finishes the installation, it will restart the Python kernel for changes to be applied. This happens automatically. Thus, you will see a message saying \"Your session crashed for an unknown reason\". You can safely ignore this message!*" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "!pip install -q condacolab\n", 55 | "import condacolab\n", 56 | "condacolab.install()" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "Now we can install PyGMT and its dependencies using a single command. The installation may take a few minutes:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "!mamba install pygmt" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Loading the PyGMT package\n", 80 | "\n", 81 | "You can load PyGMT by importing the `pygmt` Python package. Most GMT processing modules will be avialable as functions in this package. The plotting modules are methods of the `pygmt.Figure` class." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "# Load the PyGMT package. This only needs to be run once\n", 91 | "import pygmt" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "## Check the installed environment\n", 99 | "\n", 100 | "Before starting, let's first check the current environment:" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "pygmt.show_versions()" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "## Example 1" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "All figure generation in PyGMT is handled by the `pygmt.Figure` class. \n", 124 | "It has methods to add layers to your figure, like a basemap, coastlines, etc." 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": {}, 130 | "source": [ 131 | "We start a new figure by creating an instance of `pygmt.Figure`:" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "fig = pygmt.Figure()" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "We add elements to the figure using its methods. For example, lets add the global coastlines to a 15 cm wide map using the Hammer projection (**H**). \n", 148 | "Our figure will also have a nice frame with automatic ticks." 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "fig.coast(region='g', projection='H15c', frame=True, land='lightbrown', water='lightblue')" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "You can see a preview of the figure directly in the Jupyter notebook using `fig.show()`." 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [ 173 | "fig.show()" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "You can also save your figure in several graphics formats (e.g., png, pdf, jpg) using `fig.savefig()`:" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "fig.savefig(\"global.png\")" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "## Example 2" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "from pygmt.datasets import load_earth_relief\n", 206 | "\n", 207 | "grid = load_earth_relief(resolution='01d', registration='pixel')\n", 208 | "\n", 209 | "fig = pygmt.Figure()\n", 210 | "fig.basemap(region='g', projection='G200/30/12c', frame=True)\n", 211 | "fig.grdimage(grid, cmap='geo', shading=True)\n", 212 | "fig.coast(resolution='c', shorelines=True, area_thresh=1000)\n", 213 | "fig.plot(data='@hotspots.txt', style='c0.2c', fill='red')\n", 214 | "fig.colorbar()\n", 215 | "fig.show()" 216 | ] 217 | }, 218 | { 219 | "cell_type": "markdown", 220 | "metadata": {}, 221 | "source": [ 222 | "## Experiment for yourself" 223 | ] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "metadata": {}, 228 | "source": [ 229 | "Try running different things in the cells below or edit and rerun the cells above." 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "fig = pygmt.Figure()\n", 239 | "# Any Python codes here\n", 240 | "fig.show()" 241 | ] 242 | } 243 | ], 244 | "metadata": { 245 | "kernelspec": { 246 | "display_name": "Python 3 (ipykernel)", 247 | "language": "python", 248 | "name": "python3" 249 | }, 250 | "language_info": { 251 | "codemirror_mode": { 252 | "name": "ipython", 253 | "version": 3 254 | }, 255 | "file_extension": ".py", 256 | "mimetype": "text/x-python", 257 | "name": "python", 258 | "nbconvert_exporter": "python", 259 | "pygments_lexer": "ipython3", 260 | "version": "3.9.15" 261 | } 262 | }, 263 | "nbformat": 4, 264 | "nbformat_minor": 4 265 | } 266 | -------------------------------------------------------------------------------- /python-demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Try PyGMT online" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "This Jupyter lab environment has the latest PyGMT installed. You can try PyGMT with no extra install required." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "**NOTE:** Any changes will be lost when the Jupyter lab is closed. Select \"File\"->\"Download\" to save notebooks to your computer." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "To execute the code cells, select it and type `Shift + Enter` or click on the \"Run\" ► button in the menu bar. \n", 29 | "\n", 30 | "For tutorials and more examples, visit the official website: https://www.pygmt.org" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Loading the PyGMT package\n", 38 | "\n", 39 | "You can load PyGMT by importing the `pygmt` Python package. Most GMT processing modules will be avialable as functions in this package. The plotting modules are methods of the `pygmt.Figure` class." 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "# Load the PyGMT package. This only needs to be run once\n", 49 | "import pygmt" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "## Check the installed environment\n", 57 | "\n", 58 | "Before starting, let's first check the current environment:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "pygmt.show_versions()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "## Example 1" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "All figure generation in PyGMT is handled by the `pygmt.Figure` class. \n", 82 | "It has methods to add layers to your figure, like a basemap, coastlines, etc." 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "We start a new figure by creating an instance of `pygmt.Figure`:" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "fig = pygmt.Figure()" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "We add elements to the figure using its methods. For example, lets add the global coastlines to a 15 cm wide map using the Hammer projection (**H**). \n", 106 | "Our figure will also have a nice frame with automatic ticks." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "fig.coast(region='g', projection='H15c', frame=True, land='lightbrown', water='lightblue')" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "You can see a preview of the figure directly in the Jupyter notebook using `fig.show()`." 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "fig.show()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "You can also save your figure in several graphics formats (e.g., png, pdf, jpg) using `fig.savefig()`:" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [ 147 | "fig.savefig(\"global.png\")" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "## Example 2" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "from pygmt.datasets import load_earth_relief\n", 164 | "\n", 165 | "grid = load_earth_relief(resolution='01d', registration='pixel')\n", 166 | "\n", 167 | "fig = pygmt.Figure()\n", 168 | "fig.basemap(region='g', projection='G200/30/12c', frame=True)\n", 169 | "fig.grdimage(grid, cmap='geo', shading=True)\n", 170 | "fig.coast(resolution='c', shorelines=True, area_thresh=1000)\n", 171 | "fig.plot(data='@hotspots.txt', style='c0.2c', fill='red')\n", 172 | "fig.colorbar()\n", 173 | "fig.show()" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "## Experiment for yourself" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "Try running different things in the cells below or edit and rerun the cells above." 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "fig = pygmt.Figure()\n", 197 | "# Any Python codes here\n", 198 | "fig.show()" 199 | ] 200 | } 201 | ], 202 | "metadata": { 203 | "kernelspec": { 204 | "display_name": "Python 3 (ipykernel)", 205 | "language": "python", 206 | "name": "python3" 207 | }, 208 | "language_info": { 209 | "codemirror_mode": { 210 | "name": "ipython", 211 | "version": 3 212 | }, 213 | "file_extension": ".py", 214 | "mimetype": "text/x-python", 215 | "name": "python", 216 | "nbconvert_exporter": "python", 217 | "pygments_lexer": "ipython3", 218 | "version": "3.9.15" 219 | } 220 | }, 221 | "nbformat": 4, 222 | "nbformat_minor": 4 223 | } 224 | --------------------------------------------------------------------------------