-
Notifications
You must be signed in to change notification settings - Fork 229
Add tutorial for pygmt.config #482
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
Merged
seisman
merged 13 commits into
GenericMappingTools:master
from
hemmelig:config_tutorial
Oct 29, 2020
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f1d2ab0
Add tutorial for pygmt.Figure.text
hemmelig 585ed8c
Add tutorial for pygmt.config
hemmelig c0da05e
Remove pygmt.Figure.text tutorial
hemmelig 968f551
Merge branch 'master' into config_tutorial
seisman 6ec06c1
Merge branch 'master' into config_tutorial
seisman c709bbe
Apply suggestions from code review
hemmelig b84e4a2
Make changes from review
hemmelig b9d5c10
Rename config tutorial
hemmelig c225f19
Make suggested changes from review
hemmelig 175c2b4
Apply suggestions from code review
hemmelig dce7ad8
Apply suggestions from code review
hemmelig 154a719
Merge branch 'master' into config_tutorial
seisman f0cc82c
[format-command] fixes
actions-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Configuring PyGMT defaults | ||
========================== | ||
|
||
Default GMT parameters can be set globally or locally using :class:`pygmt.config` | ||
""" | ||
|
||
import pygmt | ||
|
||
######################################################################################## | ||
# Configuring default GMT parameters | ||
# ---------------------------------- | ||
# | ||
# The user can override default parameters either temporarily (locally) or permanently | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# (globally) using :meth:`pygmt.config`. The full list of default parameters that can be | ||
# changed can be at :gmt-docs:`gmt.conf.html`. | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# We demonstrate the usage of :meth:`pygmt.config` by configuring a map plot. | ||
|
||
# Start with a basic figure | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True) | ||
fig.coast(land="black", water="skyblue") | ||
|
||
fig.show() | ||
|
||
######################################################################################## | ||
# Globally overriding defaults | ||
# ---------------------------- | ||
# | ||
# The ``MAP_FRAME_TYPE`` parameter specifies the style of map frame to use, of which there | ||
# are 5 options: ``fancy`` (default, seen above), ``fancy+``, ``plain``, ``graph`` | ||
# (which does not apply to geographical maps) and ``inside``. | ||
# | ||
# The ``FORMAT_GEO_MAP`` parameter controls the format of geographical tick annotations. | ||
# The default uses degrees and minutes. Here we specify the ticks to be a decimal number | ||
# of degrees. | ||
|
||
fig = pygmt.Figure() | ||
|
||
# Configuration for the 'current figure'. | ||
pygmt.config(MAP_FRAME_TYPE="plain") | ||
pygmt.config(FORMAT_GEO_MAP="ddd.xx") | ||
|
||
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True) | ||
fig.coast(land="black", water="skyblue") | ||
|
||
fig.show() | ||
|
||
######################################################################################## | ||
# Locally overriding defaults | ||
# --------------------------- | ||
# | ||
# It is also possible to temporarily override the default parameters, which is a very | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# useful for limiting the scope of changes to a particular plot. :class:`pygmt.config` is | ||
# implemented as a context manager, which handles the setup and teardown of a GMT | ||
# session. Python users are likely familiar with the `with open(...) as file:` snippet, | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# which returns a `file` context manager. In this way, it can be used to override a parameter | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# for a single command, or a sequence of commands. An application of `pygmt.config` as a context | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# manager is shown below: | ||
|
||
fig = pygmt.Figure() | ||
|
||
# This will have a fancy+ frame | ||
with pygmt.config(MAP_FRAME_TYPE="fancy+"): | ||
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True) | ||
fig.coast(land="black", water="skyblue") | ||
|
||
# This figure retains the default "fancy" frame | ||
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", Y="-10c", frame=True) | ||
fig.coast(land="black", water="skyblue") | ||
hemmelig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.