-
Notifications
You must be signed in to change notification settings - Fork 245
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
Changes from 20 commits
749816d
a8ff9e7
7f516e7
11a1c95
54dc8f5
91c9b22
ecadf04
31a2be3
a61d561
d8722f4
f097459
0f736fb
c330bfd
afa8d9a
bea208e
5748ef7
3b8651f
90c84ea
7552c6a
e7aa9da
4858d70
f60f4cd
0ea30e2
184a46e
218c321
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """ | ||
| Inset map showing a rectangle region | ||
| ------------------------------------ | ||
|
|
||
| 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 can be customized. Plotting methods called within the | ||
| ``with`` statement plot into the inset figure. | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
core-man marked this conversation as resolved.
Outdated
|
||
| import pygmt | ||
|
|
||
| # Set the region of the main figure | ||
| region = [137.5, 141, 34, 37] | ||
|
|
||
| fig = pygmt.Figure() | ||
|
|
||
| # Plot the base map of the main figure | ||
| fig.basemap(region=region, projection="M12c", frame=["WSne", "af"]) | ||
|
|
||
| # Set the land color to "lightbrown", the water color to "azure1", the shorelines | ||
|
core-man marked this conversation as resolved.
Outdated
|
||
| # width to "2p", the area threshold to 1000 km^2 for the main figure | ||
|
core-man marked this conversation as resolved.
Outdated
|
||
| fig.coast(land="lightbrown", water="azure1", shorelines="2p", area_thresh=1000) | ||
|
|
||
| # Create an inset map, setting the position to bottom right, the width to | ||
| # 3 centimeters, the height to 3.6 centimeters, and the x- and y-offsets to | ||
| # 0.1 centimeters. Draws a rectangular box around the inset with a fill color | ||
|
core-man marked this conversation as resolved.
Outdated
|
||
| # of "white" and a pen of "1p". | ||
| with fig.inset(position="jBR+w3c/3.6c+o0.1c", box="+gwhite+p1p"): | ||
| # Plot the Japan main land in the inset using coast. "M?" means Mercator | ||
|
Member
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 it's not too much work, would it be possible to change to a different projection system besides Mercator? E.g. Universal Transverse Mercator (U)? I worry about all the people who are going to use Mercator for their publications because it was a default copied from some gallery example!
Member
Author
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 think it's really a good suggestion. Maybe we should add a tutorial to discuss how to choose projection. But I am not very familiar with the difference between different projections. I test fig.basemap(region=region, projection="U54S/12c", frame=["WSne", "af"])
...
# Inset
fig.coast(
region=[129, 146, 30, 46],
projection="U54S/?",
...
)
Member
Author
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. Now there are six additional examples with different map projections:
Member
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.
Not an expert with GMT projection codes either, but I think it's ok to have it a little oblique. Maybe take a look at https://docs.generic-mapping-tools.org/6.1/gallery/ex28.html which managed a square-ish output somehow. P.S. Please try to keep pinging of teams to a minimal (e.g. just one team if possible instead of 2 or 3). Not everyone checks their notification area all the time, and it's best not to spam people's notification area with dozens of mentions if they decide to go away for the weekend.
Member
Author
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.
Okay~ Thanks for the suggestion. Actually, I don't know which is the best one for help. I guess usually I can use python-contributors?
Member
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. Personally I would 1) just try and solve it myself first, 2) ask a question without pinging anyone (it's ok to leave a PR like that for a few days, those who are interested will usually answer) and then 3) ping someone from the team if you get no reply. I realize it's getting close to the release date and we all want our PRs to be merged ASAP, but please try and be considerate of people's inboxes too! That said, I think the slightly oblique Japan map on a UTM projection is fine, it actually looks a bit cool to be honest! After trying for a bit, I think (though not 100%) that the only way to get a rectangular/non-oblique map is to plot a grid first in linear projection system (e.g. -Jx1:250000) which would require knowing the region bounds in UTM unit metres rather than lon/lat. This will be a bit too complicated for a gallery example, so let's just keep it easy and use
Member
Author
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.
Great~
I would like to keep
Member
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 pretty sure users can plot symbols/data/lines on a UTM map just as usual compared to a Mercator map right? I.e. use the same georeferenced data in longitude/latitude. The projection only distorts the shape of the Earth, not the data points or how they can be plotted.
Yes I agree that a tutorial for projections is good (though this is a big geography lesson in itself).
Member
Author
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.
Good to know. It seems that my understanding is a little wrong. Done in 0ea30e2. |
||
| # projection with map width automatically determined from the inset width. | ||
| # Highlight the Japan area in "lightbrown" | ||
| # and draw its outline with a pen of "0.2p". | ||
| fig.coast( | ||
| region=[129, 146, 30, 46], | ||
| projection="M?", | ||
| dcw="JP+glightbrown+p0.2p", | ||
| area_thresh=10000, | ||
| ) | ||
| # Plot a rectangle ("r") in the inset map to show the area of the main figure. | ||
| # "+s" means that the first two columns are the longitude and latitude of | ||
| # the bottom left corner of the rectangle, and the last two columns the | ||
| # longitude and latitude of the uppper right corner. | ||
| rectangle = [[region[0], region[2], region[1], region[3]]] | ||
| fig.plot(data=rectangle, style="r+s", pen="2p,blue") | ||
|
|
||
| fig.show() | ||

Uh oh!
There was an error while loading. Please reload this page.