-
Notifications
You must be signed in to change notification settings - Fork 235
Add a gallery example of inset map showing a rectangle region #1020
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
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
749816d
Add a inset gallery
core-man a8ff9e7
Re-format
core-man 7f516e7
Use np.array instead of temporal files
core-man 11a1c95
Merge branch 'master' into inset-gallery
core-man 54dc8f5
Use a list to plot the rectangle
core-man 91c9b22
Apply suggestions from code review
core-man ecadf04
Explain r+s
core-man 31a2be3
Merge branch 'master' into inset-gallery
core-man a61d561
Tiny update comments
core-man d8722f4
Fix
core-man f097459
Fix a bug
core-man 0f736fb
Merge branch 'master' into inset-gallery
core-man c330bfd
Merge branch 'master' into inset-gallery
core-man afa8d9a
Merge branch 'master' into inset-gallery
core-man bea208e
Apply suggestions from code review
core-man 5748ef7
Enlarge the inset region
core-man 3b8651f
Use underscore for .py file name
core-man 90c84ea
Delete duplicate .py file
core-man 7552c6a
Merge branch 'master' into inset-gallery
core-man e7aa9da
Move inset_rectangle_region.py to embellishments dir
core-man 4858d70
Apply suggestions from code review
core-man f60f4cd
Merge branch 'master' into inset-gallery
core-man 0ea30e2
Use UTM instead of Mercator
core-man 184a46e
Merge branch 'inset-gallery' of github.com:core-man/pygmt into inset-…
core-man 218c321
Fix title
core-man 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """ | ||
| Inset with an rectangle | ||
| ------------------------ | ||
|
|
||
| The :meth:`pygmt.Figure.inset` method adds an inset figure inside a larger | ||
| figure. The function is called using a ``with`` statement, and its position, | ||
| box, offset, and margin parameters are set. Plotting methods called within the | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``with`` statement plot into the inset figure. | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pygmt | ||
| from pygmt.helpers import GMTTempFile | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Set the region to be near Tokyo | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| region = np.array([139.2, 140.5, 34.8, 36]) | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| fig = pygmt.Figure() | ||
|
|
||
| # Plot the base map of the primary figure | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fig.basemap( | ||
| region=region, | ||
| projection="M12c", | ||
| frame=["WSne", "af"], | ||
| ) | ||
|
|
||
| # Set the land color to "lightbrown", the water to "azure1", the shorelines | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # width to "2p", the smallest area to 1000 km2 for the primary figure | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fig.coast( | ||
| land="lightbrown", | ||
| water="azure1", | ||
| shorelines="2p", | ||
| area_thresh=1000, | ||
| ) | ||
|
|
||
| # Create an inset, setting the position to bottom left, the width to | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 3 centimeters, the height to 3.6 centimeters, and the x- and y-offsets to | ||
core-man marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 0.2 centimeters. Draws a rectangular box around the inset with a fill color | ||
| # of "white" and a pen of "1p". | ||
| with fig.inset(position="jBL+w3c/3.6c+o0.1c", box="+gwhite+p1p"): | ||
| # Plot the Japan main land in the inset using coast | ||
| # "M?" means Mercator projection with map width automatically determined | ||
| # based on the width in the position parameter of inset. | ||
| fig.coast( | ||
| region=[129, 146, 30, 46], | ||
| projection="M?", | ||
| dcw="JP+glightbrown+p0.2p", | ||
| area_thresh=10000, | ||
| ) | ||
| # Plot a rectangle in the inset map to show the area of the primary figure | ||
| with GMTTempFile() as temp_file: | ||
| with open(temp_file.name, "w") as f: | ||
| f.write("{} {} {} {}".format(region[0], region[2], region[1], region[3])) | ||
| fig.plot( | ||
| data=temp_file.name, | ||
| style="r+s", | ||
| pen="1p,blue", | ||
| ) | ||
core-man marked this conversation as resolved.
Outdated
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.