You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @eyalshimony, thanks for trying PyGMT! So it's a bit unintuitive, but it's best not to set the projection width in the inset plot. Try this instead:
withfig.inset(position="jTR+w3c", box="+pblack"):
# Use a plotting function to create a figure inside the insetfig.coast(
region=[-125, -110, 30, 45],
projection="M?c",
land="gray",
borders=[1, 2],
shorelines="1/thin",
water="white"
)
fig.plot(x=-117.55, y=35.7, size=[0.2], style="c", frame="afg", color="black")
Specifically, use projection="M?c" instead of projection="M3c", which means the size is scaled automatically to the inset box. This should produce:
You may need to adjust the width in fig.inset(position="jTR+w3c", ...) to make the box be the correct size.
I am sorry, I checked it and it actually ruins some stuff in the example. Most importantly, the highlighting stops working. I do not know enough about this in order to fix it, so I think it is best be left to the experts.
Yes, I understood it afterwards but as I said above changing the projection along your recommendations ruins the highlighting. I have no idea why, so I think it would be better if you'd fix it.
Hmm yeah, I just tried using M?c for that example but don't understand why the red highlight is incorrect either 😅 You're still welcome to open the Pull Request if you'd like, that way it will be faster for someone to check it and give suggestions on what to do. But I understand if you're short on time.
Hmm yeah, I just tried using M?c for that example but don't understand why the red highlight is incorrect either sweat_smile You're still welcome to open the Pull Request if you'd like, that way it will be faster for someone to check it and give suggestions on what to do. But I understand if you're short on time.
We have to use M?, not M?c, because ? will be repalced by an automatic width like 1.5i, so M?c becomes M1.5ic, which is invalid.
gmt begin map
gmt coast -R-74/-69.5/41/43 -JM15c -Baf -Wthin -Clightblue -Glightyellow
gmt inset begin -DjBL+w3c+o0.5c/0.2c -F+pblack+gwhite
gmt coast -R-80/-65/35/50 -JM?+du -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
gmt inset end
gmt end show
For the coast call in the inset, users have to use -JM?+du so that the highlight is placed at the right position. Other forms like -JM? and -JM?+dw don't work.
@PaulWessel The use of -JM?+du is not intuitive. Is there anything GMT can do to improve it?
The key thing that happens is the unfortunate selection of -R and inset size (square). That map is not square, so GMT finds that the hight with -JM3c is 4.08581069804c which exceeds the square so it applies the scale 3/4.08581069804 so that the max dimension is 3c. That means the width is actually 2.20274522369c which is what is used when -JM? is converted to -JM2.20274522369c. However, coast passes the buck to the function gmt_DCW_operation that plots the -E stuff and clearly there is some issues with what projection parameters are used. I will have to debug to see why, and once I understand what happens it should be doable to fix it.
I am not sure what to do for the unfortunate selection of -R and a square inset. It is not easy for the user to know what is the best -R that gives a square map for some projection. Perhaps we need to come up with a better implementation here. Maybe the inset command should be +w3c/? to indicate we want GMT to compute the height of the inset since it is unknown. Or similarly +w?/3c to fix the height and let the width be determined. To me, that seems reasonable: The user selects the region and we compute the missing dimension.
And gmt_DCW_operation ends up making a virtual dataset and passing it via a call to psxy where the command string contains -J. So I think it picks up the -Jm3c since the change to -Jm2.2c happens internally and the history is not updated. I think if I update the history it may be work if it happens before the cal.
@eyalshimony Here is a better solution for you case. So instead of specifying +w3c in position, you can set region and projection parameter so that GMT can automatically determine both width and height of the inset for you.
Activity
weiji14 commentedon May 23, 2022
Hi @eyalshimony, thanks for trying PyGMT! So it's a bit unintuitive, but it's best not to set the projection width in the inset plot. Try this instead:
Specifically, use
projection="M?c"instead ofprojection="M3c", which means the size is scaled automatically to the inset box. This should produce:You may need to adjust the width in
fig.inset(position="jTR+w3c", ...)to make the box be the correct size.eyalshimony commentedon May 23, 2022
Thanks for the quick response!
It may be helpful for other users if you'll correct the example in https://www.pygmt.org/v0.3.0/tutorials/inset.html accordingly.
weiji14 commentedon May 23, 2022
Yes that would be a good idea. Would you like to try making a quick change at https://github.com/GenericMappingTools/pygmt/edit/main/examples/tutorials/advanced/insets.py?
eyalshimony commentedon May 23, 2022
I submitted the change
eyalshimony commentedon May 23, 2022
I am sorry, I checked it and it actually ruins some stuff in the example. Most importantly, the highlighting stops working. I do not know enough about this in order to fix it, so I think it is best be left to the experts.
michaelgrund commentedon May 23, 2022
Where did you submit it? Just take a look at our contributing guide on how to create a PR for fixing issues 😉.
weiji14 commentedon May 23, 2022
I see you've made the change at https://github.com/eyalshimony/pygmt/tree/patch-1. If you click on the 'Contribute' button and then Open Pull Request, we'll be able to see it.
eyalshimony commentedon May 23, 2022
Yes, I understood it afterwards but as I said above changing the projection along your recommendations ruins the highlighting. I have no idea why, so I think it would be better if you'd fix it.
weiji14 commentedon May 23, 2022
Hmm yeah, I just tried using
M?cfor that example but don't understand why the red highlight is incorrect either 😅 You're still welcome to open the Pull Request if you'd like, that way it will be faster for someone to check it and give suggestions on what to do. But I understand if you're short on time.seisman commentedon May 24, 2022
I'm reopening the issue to track the potential issue in https://github.com/GenericMappingTools/pygmt/blob/main/examples/tutorials/advanced/insets.py
seisman commentedon May 24, 2022
We have to use
M?, notM?c, because?will be repalced by an automatic width like1.5i, soM?cbecomesM1.5ic, which is invalid.eyalshimony commentedon May 24, 2022
With M? the highlighting exists, but it is in the wrong location
seisman commentedon May 24, 2022
Yes, I can confirm the issue. After some tries, I think the only one that works is
projection="M?+du".seisman commentedon May 24, 2022
Here is a GMT bash script to reproduce the issue:
For the
coastcall in the inset, users have to use-JM?+duso that the highlight is placed at the right position. Other forms like-JM?and-JM?+dwdon't work.@PaulWessel The use of
-JM?+duis not intuitive. Is there anything GMT can do to improve it?seisman commentedon May 26, 2022
Ping @PaulWessel on #1930 (comment)
PaulWessel commentedon May 26, 2022
Yep, saw this issue but up to my neck in issues (not all GMT), so I will get to it when I can.
PaulWessel commentedon May 26, 2022
The key thing that happens is the unfortunate selection of -R and inset size (square). That map is not square, so GMT finds that the hight with
-JM3c is 4.08581069804cwhich exceeds the square so it applies the scale 3/4.08581069804 so that the max dimension is 3c. That means the width is actually 2.20274522369c which is what is used when-JM?is converted to-JM2.20274522369c. However, coast passes the buck to the function gmt_DCW_operation that plots the -E stuff and clearly there is some issues with what projection parameters are used. I will have to debug to see why, and once I understand what happens it should be doable to fix it.I am not sure what to do for the unfortunate selection of -R and a square inset. It is not easy for the user to know what is the best -R that gives a square map for some projection. Perhaps we need to come up with a better implementation here. Maybe the inset command should be
+w3c/?to indicate we want GMT to compute the height of the inset since it is unknown. Or similarly+w?/3cto fix the height and let the width be determined. To me, that seems reasonable: The user selects the region and we compute the missing dimension.PaulWessel commentedon May 26, 2022
And gmt_DCW_operation ends up making a virtual dataset and passing it via a call to psxy where the command string contains -J. So I think it picks up the
-Jm3csince the change to-Jm2.2chappens internally and the history is not updated. I think if I update the history it may be work if it happens before the cal.seisman commentedon May 27, 2022
@eyalshimony Here is a better solution for you case. So instead of specifying
+w3cinposition, you can setregionandprojectionparameter so that GMT can automatically determine both width and height of the inset for you.Unfortunately,
inset'sregionandprojectionparameters are not aliased in PyGMT v0.6.1. As a workaround, you can use the following code instead: