-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the starter tutorial introduction #1607
Changes from all commits
62d3f3f
ef4d987
8f5c49c
41814f3
3661ada
5605b9d
793b555
77799f0
1ab117c
962d05d
a9441a2
d6e7c1e
943c51f
016b7f7
33fb360
473a63b
bd99bcf
cf98638
9131163
b9aa8d6
03bc80a
3c53e55
c880bd7
b89e708
ae030ba
0e8efcb
af13124
416175b
3be0dca
3479d32
94b9976
cd7f278
748c12b
c02cdaf
b792c6c
9604d7f
b1e3b5e
7fe3ee1
1f3a071
380d4af
e90bc27
64dfe0a
3ae1a1e
75fb36c
a4a417c
7c1ffec
2024b6c
f912e75
dfc996d
892a14c
3ce6a71
237e141
9f5568f
5910c38
894a1cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ clean: | |
rm -rf api/generated | ||
rm -rf gallery | ||
rm -rf tutorials | ||
rm -rf get-started | ||
rm -rf projections |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Intro to PyGMT | ||
============== | ||
|
||
Welcome to PyGMT! This tutorial is designed to teach the basic concepts to | ||
make a map in PyGMT. | ||
|
||
**About this tutorial** | ||
|
||
This tutorial assumes that PyGMT has been successfully | ||
:doc:`installed </install>`. A quick way to test this is to type | ||
``import pygmt`` in a Python IDE or | ||
`Jupyter <https://jupyter.org>`__ Notebook. | ||
|
||
This tutorial will progressively cover PyGMT plotting concepts, and later | ||
examples will use concepts explained in previous examples. It will not | ||
cover all PyGMT modules. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
""" | ||
1. Making your first figure | ||
=========================== | ||
|
||
This tutorial page covers the basics of creating a figure using PyGMT - a | ||
Python wrapper for the Generic Mapping Tools (GMT). It will only use | ||
the ``coast`` module for plotting. Later examples will address other PyGMT | ||
modules. | ||
""" | ||
|
||
maxrjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
############################################################################### | ||
# Setting up the development environment | ||
# -------------------------------------- | ||
# | ||
# PyGMT can be used in both a Python script and a notebook environment, such | ||
# as Jupyter. The tutorial's recommended method is to use a notebook, and the | ||
# code will be for a notebook environment. | ||
|
||
|
||
############################################################################### | ||
# Loading the library | ||
# ------------------- | ||
# | ||
# The first step is to import ``pygmt``. All modules and figure generation is | ||
# accessible from the :mod:`pygmt` top level package. | ||
|
||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# sphinx_gallery_thumbnail_number = 4 | ||
import pygmt | ||
|
||
############################################################################### | ||
# Creating a figure | ||
# ----------------- | ||
# | ||
# All figure generation in PyGMT is handled by the :class:`pygmt.Figure` class. | ||
# Start a new figure by creating an instance of this class: | ||
|
||
fig = pygmt.Figure() | ||
|
||
############################################################################### | ||
# To add to a plot object (``fig`` in this example), the PyGMT module is used | ||
# as a method on the class. This example will use the module ``coast``, which | ||
# can be used to create a map without any other modules or external data. The | ||
# ``coast`` module plots the coastlines, borders, and bodies of water using a | ||
# database that is included in GMT. | ||
# | ||
# First, a region for the figure must be selected. This example will plot some | ||
# of the coast of Maine in the northeastern US. A Python list can be passed to | ||
# the ``region`` argument with the minimum and maximum X-values (longitude) | ||
# and the minimum and maximum Y-values (latitude). For this example, the | ||
# minimum (bottom left) coordinates are (N43.75, W69) and the maximum (top | ||
# right) coordinates are (N44.75, W68). Negative values can be passed for | ||
# latitudes in the southern hemisphere or longitudes in the western hemisphere. | ||
# | ||
# In addition to the region, an argument needs to be passed to ``coast`` to | ||
# tell it what to plot. In this example, ``coast`` will be told to plot the | ||
# shorelines by passing the Boolean value ``True`` to the ``shorelines`` | ||
# parameter. The ``shorelines`` parameter has other options for finer control, | ||
# but setting it to ``True`` uses the default values. | ||
|
||
fig.coast(region=[-69, -68, 43.75, 44.75], shorelines=True) | ||
|
||
############################################################################### | ||
# To see the figure, call :meth:`pygmt.Figure.show`. | ||
|
||
fig.show() | ||
|
||
############################################################################### | ||
# Color the land and water | ||
# ------------------------ | ||
# | ||
# This figure plots all of the coastlines in the given region, but it does not | ||
# indicate where the land and water are. Color values can be passed to ``land`` | ||
# and ``water`` to set the colors on the figure. | ||
# | ||
# When plotting colors in PyGMT, there are multiple | ||
# :gmt-docs:`color codes <gmtcolors.html>`, that can be used. This includes | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# standard GMT color names (like ``skyblue``), R/G/B levels (like ``0/0/255``), | ||
# a hex value (like ``#333333``), or a graylevel (like ``50``). For this | ||
# example, GMT color names are used. | ||
|
||
fig = pygmt.Figure() | ||
fig.coast( | ||
region=[-69, -68, 43.75, 44.75], | ||
shorelines=True, | ||
land="lightgreen", | ||
water="lightblue", | ||
) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Set the projection | ||
# ------------------ | ||
# | ||
# This figure now has its colors set, but there is no projection or size | ||
# set for the map. Both of these values are set using the ``projection`` | ||
# parameter. | ||
# | ||
# The appropriate projection varies for the type of map. The available | ||
# projections are explained in the :doc:`projection </projections/index>` | ||
# gallery. For this example, the Mercator projection is set using ``"M"``. | ||
# The width of the figure will be 10 centimeters, as set by ``"10c"``. The map | ||
# size can also be set in inches using "i" (e.g. a 5 inch wide Mercator | ||
# projection would use ``"M5i"``). | ||
|
||
fig = pygmt.Figure() | ||
fig.coast( | ||
region=[-69, -68, 43.75, 44.75], | ||
shorelines=True, | ||
land="lightgreen", | ||
water="lightblue", | ||
projection="M10c", | ||
) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Add a frame | ||
# ----------- | ||
# | ||
# While that the map's colors, projection, and size have been set, the region | ||
# that is being displayed is not apparent. A frame can be added to | ||
# annotate the latitude and longitude of the region. | ||
# | ||
# The ``frame`` parameter is used to add a frame to the figure. For now, it | ||
# will be set to ``True`` to use default settings, but later tutorials will | ||
# show how ``frame`` can be used to customize the axes, gridlines, and titles. | ||
|
||
fig = pygmt.Figure() | ||
fig.coast( | ||
region=[-69, -68, 43.75, 44.75], | ||
shorelines=True, | ||
land="lightgreen", | ||
water="lightblue", | ||
projection="M10c", | ||
frame=True, | ||
) | ||
fig.show() | ||
|
||
############################################################################### | ||
# Additional exercises | ||
# -------------------- | ||
# | ||
# This is the end of the first tutorial. Here are some additional exercises | ||
# for the concepts that were discussed: | ||
# | ||
# 1. Make a map of Germany using its ISO country code ("DE"). Pass the ISO | ||
# code as a Python string to the ``region`` parameter. | ||
# | ||
# 2. Change the color of the land to "khaki" and the water to "azure". | ||
# | ||
# 3. Change the color of the lakes (using the ``lakes`` parameter) to "red". | ||
# | ||
# 4. Create a global map. Set the region to "d" to center the map at the Prime | ||
# Meridian or "g" to center the map at the International Date Line. When the | ||
# region is set without using a list full of integers or floating numbers, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If I understand you correctly, you mean passing a string like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually referring to passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you meant. I also agree that a string like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, you could pass in a list of strings like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but it's not commonly used, and better not to introduce too many options. |
||
# the argument needs to be passed as a Python string. Create a 15 centimeter | ||
# map using the Mollwide ("W") projection. |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a thought, should we add a binder link so that people can 'follow along' with the tutorial interactively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weiji14 I'm not familiar with using binder; could you make a code suggestion to add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's better to add the binder link in a separate PR. Ideally, we should modify the template to automatically add the binder links for each example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sounds good to me.