Skip to content
Merged
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
749816d
Add a inset gallery
core-man Mar 8, 2021
a8ff9e7
Re-format
core-man Mar 8, 2021
7f516e7
Use np.array instead of temporal files
core-man Mar 8, 2021
11a1c95
Merge branch 'master' into inset-gallery
core-man Mar 9, 2021
54dc8f5
Use a list to plot the rectangle
core-man Mar 9, 2021
91c9b22
Apply suggestions from code review
core-man Mar 9, 2021
ecadf04
Explain r+s
core-man Mar 9, 2021
31a2be3
Merge branch 'master' into inset-gallery
core-man Mar 9, 2021
a61d561
Tiny update comments
core-man Mar 10, 2021
d8722f4
Fix
core-man Mar 10, 2021
f097459
Fix a bug
core-man Mar 10, 2021
0f736fb
Merge branch 'master' into inset-gallery
core-man Mar 10, 2021
c330bfd
Merge branch 'master' into inset-gallery
core-man Mar 10, 2021
afa8d9a
Merge branch 'master' into inset-gallery
core-man Mar 10, 2021
bea208e
Apply suggestions from code review
core-man Mar 11, 2021
5748ef7
Enlarge the inset region
core-man Mar 11, 2021
3b8651f
Use underscore for .py file name
core-man Mar 11, 2021
90c84ea
Delete duplicate .py file
core-man Mar 11, 2021
7552c6a
Merge branch 'master' into inset-gallery
core-man Mar 12, 2021
e7aa9da
Move inset_rectangle_region.py to embellishments dir
core-man Mar 12, 2021
4858d70
Apply suggestions from code review
core-man Mar 12, 2021
f60f4cd
Merge branch 'master' into inset-gallery
core-man Mar 12, 2021
0ea30e2
Use UTM instead of Mercator
core-man Mar 12, 2021
184a46e
Merge branch 'inset-gallery' of github.com:core-man/pygmt into inset-…
core-man Mar 12, 2021
218c321
Fix title
core-man Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/gallery/embellishments/inset_rectangle_region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Inset map showing a rectangle region
------------------------------------
Comment thread
core-man marked this conversation as resolved.
Outdated

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
Comment thread
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
Comment thread
core-man marked this conversation as resolved.
Outdated
# width to "2p", the area threshold to 1000 km^2 for the main figure
Comment thread
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
Comment thread
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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!

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 U, the figure looks a little oblique. Ping @GenericMappingTools/python @GenericMappingTools/python-contributors for any suggestion?

fig.basemap(region=region, projection="U54S/12c", frame=["WSne", "af"])
...
# Inset
    fig.coast(
        region=[129, 146, 30, 46],
        projection="U54S/?",
        ...
    )

Screenshot from 2021-03-12 15-06-46

@core-man core-man Mar 12, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now there are six additional examples with different map projections:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 U, the figure looks a little oblique. Ping @GenericMappingTools/python @GenericMappingTools/python-contributors for any suggestion?

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.

@core-man core-man Mar 12, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 U54S/12c.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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!

Great~

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 U54S/12c.

I would like to keep M for the following reasons: 1) If we assume that PyGMT users will copy the code to use for their own figures, I think they usually will plot symbols/data/lines/... in the figure, too. If we use U instead of M, they will also have to face the issue of how to plot those things in a UTM map. 2) We may have a tutorial about how to use projection in the future and GMT users should know how to choose a better projection themselves.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep M for the following reasons: 1) If we assume that PyGMT users will copy the code to use for their own figures, I think they usually will plot symbols/data/lines/... in the figure, too. If we use U instead of M, they will also have to face the issue of how to plot those things in a UTM map.

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.

  1. We may have a tutorial about how to use projection in the future and GMT users should know how to choose a better projection themselves.

Yes I agree that a tutorial for projections is good (though this is a big geography lesson in itself).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep M for the following reasons: 1) If we assume that PyGMT users will copy the code to use for their own figures, I think they usually will plot symbols/data/lines/... in the figure, too. If we use U instead of M, they will also have to face the issue of how to plot those things in a UTM map.

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.

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()