# How to crop the region in PyGMT?

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402>\
**Category:** PyGMT Q&A\
**Created:** [November 6, 2023, 6:50am UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402 "2023-11-06T06:50:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anirudh](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@anirudh](https://forum.generic-mapping-tools.org/u/anirudh)\
**Post date:** [November 6, 2023, 6:50am UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/1 "2023-11-06T06:50:37Z")

</div>

I’m plotting a map of great circle ray paths from set of co-ordinates to another set, so initially I’m assigning a region to the grid. In the final output I need the same result but just for subset of the region/cropping the map to a new region within the grid. How should I approach this?

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [November 6, 2023, 5:23pm UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/2 "2023-11-06T17:23:12Z")

</div>

Repeat the first plot call with the new « region » (with a shift of the picture of course)?

---

<div class="post-metadata">

**Author:** ![anirudh](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@anirudh](https://forum.generic-mapping-tools.org/u/anirudh)\
**Post date:** [November 7, 2023, 11:37am UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/3 "2023-11-07T11:37:19Z")

</div>

Actually I’m unable to dow that, once after the things get plotted and I crop it to new region the great circle lines are disappearing because the cropped region I’m interested in doesn’t contain the other end of co-ordinates which form the ray paths

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [November 7, 2023, 12:04pm UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/4 "2023-11-07T12:04:52Z")

</div>

Hello @anirudh,

Welcome to the GMT forum 🙂!

Unfortunately, I am having difficulty understanding your issue. I feel it would helpful if you could provide a code example demonstrating your issue.

Based on your last post, it sounds a bit like setting the `no_clip` parameter of `Figure.plot` to `True` could be helpful for you. However, `no_clip` actually does not apply to lines and polygons (for GMT 6.4.0, [https://docs.generic-mapping-tools.org/6.4/plot.html#n](https://docs.generic-mapping-tools.org/6.4/plot.html#n)).

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [November 7, 2023, 7:40pm UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/5 "2023-11-07T19:40:49Z")

</div>

Maybe OP doesn’t know how to play with `-Bafg` parameters in python ?

---

<div class="post-metadata">

**Author:** ![anirudh](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@anirudh](https://forum.generic-mapping-tools.org/u/anirudh)\
**Post date:** [November 8, 2023, 6:42am UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/6 "2023-11-08T06:42:11Z")

</div>

Actually I’m new to PyGMT itself and not well versed in GMT. Yeah I will provide you the example code

```
import numpy as np
import pygmt
import pandas as pd

fig = pygmt.Figure()

grid = pygmt.datasets.load_earth_relief(resolution="10m", region = [lat1, lon1, lat2, lon2])
fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="geo")

#reading excel file
for i in range(0, len(rows)): #plotting ray paths
            if df.Final[i] == 'yes':
                point_1 = []
                point_1.insert(0, df.Lon[i])
                point_1.insert(1, df.Lat[i])
                main_point = main_cord[j]
                data = np.array([point_1 + main_point])
                fig.plot(data=data, style="=1c+a+s", pen="1p,red", fill="red3")

fig.show()

```

Like this is the code format so after the ray paths are plotted I need canvas to show me only the desired region extent which is  
region2 = [lat’1, lon’1, lat’2, lon’2]

But,

1. I’m unable to specify the fig to the region2 at end of the code - Its just overlaying new grid on the original region.
2. If I specify region2 directly in the beginning of the code, ray path vectors are not plotted as the other set of co-ordinates exist outside region2

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [November 8, 2023, 11:49am UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/7 "2023-11-08T11:49:48Z")

</div>

@anirudh thanks providing an code example!

Can you please try option 2 together with setting the `no_clip` parameter to `True` in `fig.plot`:

```python
fig.plot(data=data, style="=1c+a+s", pen="1p,red", fill="red3", no_clip=True)

```

If this dose not fix your issue we also need your input data (i.e., what is read into the pandas DataFrame `df`) to have a more detailed look at your problem.

* * *

One comment regarding your study area set via the `region` parameter: You have to give it in the order `lon1, lon2, lat1, lat2`.

---

<div class="post-metadata">

**Author:** ![anirudh](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@anirudh](https://forum.generic-mapping-tools.org/u/anirudh)\
**Post date:** [November 10, 2023, 1:26pm UTC](https://forum.generic-mapping-tools.org/t/how-to-crop-the-region-in-pygmt/4402/9 "2023-11-10T13:26:01Z")

</div>

Thank you very much, `no_clip=True` worked
