# Methods to extract pixel coordinates after plotting

**URL:** <https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987>\
**Category:** PyGMT Q&A\
**Created:** [June 1, 2023, 7:34pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987 "2023-06-01T19:34:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![xdhqyz](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xdhqyz](https://forum.generic-mapping-tools.org/u/xdhqyz)\
**Post date:** [June 1, 2023, 7:34pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/1 "2023-06-01T19:34:30Z")

</div>

Hello,

I plot rotated geological formation polygons outputted by another tool called pyGPlates (coordinates in longitude and latitude). I would like to have a way to know where the plotted polygons are located in terms of pixel coordinates (relative to the generated image). I wonder if there is a way to know such information while using Fig.plot() or any other similar functions.

Example:

 ![china-100ma](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/6/6eede048bb158cd24996b80b78bbbc4f94d51e51.png)

Above is the image I plotted using Fig.plot(). I would like to know the pixel coordinates of those colorful polygons in the middle.

Thanks for any help in advance.

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [June 6, 2023, 2:43pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/2 "2023-06-06T14:43:30Z")

</div>

Hi @xdhqyz!! Welcome to the GMT Forum.

Do you have a file of that colorful polygons? Could you share here?

---

<div class="post-metadata">

**Author:** ![xdhqyz](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xdhqyz](https://forum.generic-mapping-tools.org/u/xdhqyz)\
**Post date:** [June 6, 2023, 6:33pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/3 "2023-06-06T18:33:10Z")

</div>

Hello Esteban,

Thanks for the reply. Here’s a file that was generated by pyGPlates. The system does not allow uploading of .gmt file format so I renamed it to .txt. Please change it back to .gmt when running. [reconstructed\_geom.gmt.txt](https://forum.generic-mapping-tools.org/uploads/short-url/reQqDtDJk3m5Du5NmQNjefujMOK.txt) (21.8 KB)

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [June 6, 2023, 7:09pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/4 "2023-06-06T19:09:20Z")

</div>

I think that you could try something like this to get the X and Y positions (in cm) of each point of the polygon.

`gmt mapproject -Rg reconstructed_geom.gmt.txt -JW15c`

Just change the value of R and J to your values.

To get the pixels instead, I think that you would need to multiply by the resolution of your image (Pixels per cm).  
Be careful with the frame and anotations outside the map.

---

<div class="post-metadata">

**Author:** ![xdhqyz](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xdhqyz](https://forum.generic-mapping-tools.org/u/xdhqyz)\
**Post date:** [June 6, 2023, 8:47pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/5 "2023-06-06T20:47:58Z")

</div>

Thank you. Since we are using PyGMT, may I ask if pygmt.project is the equivalent function of gmt mapproject?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [June 6, 2023, 9:00pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/6 "2023-06-06T21:00:48Z")

</div>

No, that is the equivalent of **gmt project**.

---

<div class="post-metadata">

**Author:** ![xdhqyz](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xdhqyz](https://forum.generic-mapping-tools.org/u/xdhqyz)\
**Post date:** [June 6, 2023, 9:05pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/7 "2023-06-06T21:05:02Z")

</div>

So is there no equivalent of mapproject in pygmt?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [June 6, 2023, 9:21pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/8 "2023-06-06T21:21:44Z")

</div>

The pyGMT users/developers can answer that - I cannot.

---

<div class="post-metadata">

**Author:** ![xdhqyz](https://avatars.discourse-cdn.com/v4/letter/x/b5ac83/32.png) [@xdhqyz](https://forum.generic-mapping-tools.org/u/xdhqyz)\
**Post date:** [June 6, 2023, 9:23pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/9 "2023-06-06T21:23:28Z")

</div>

Okay I see. Thank you anyways

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [June 6, 2023, 10:00pm UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/10 "2023-06-06T22:00:34Z")

</div>

Toe extend @Esteban82’s example to give integer pixels, you would need something like this (again -R -J on you) and of course do it in pyGMT:

**echo 10 10 | gmt mapproject -Rg -JW15c | gmt math STDIN -Ca 300 MUL RINT =**

This says that lon = 10, lat = 10 has pixel coordinates

**145 1278**

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [June 7, 2023, 11:43am UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/11 "2023-06-07T11:43:38Z")

</div>

I have a doubt. Why 300? Is not 300 the resolution in pixels per inch? Should we use the resolution of pixel per centimeters instead?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [June 8, 2023, 7:05am UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/12 "2023-06-08T07:05:07Z")

</div>

Wel, this is all tied into PROJ\_LENGTH\_UNIT. If inch then 300 if dpi is 300, else if cm then dry/2.54.

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [June 12, 2023, 3:21am UTC](https://forum.generic-mapping-tools.org/t/methods-to-extract-pixel-coordinates-after-plotting/3987/13 "2023-06-12T03:21:59Z")

</div>

`mapproject` is not wrapped in PyGMT yet. There is already a feature request ([https://github.com/GenericMappingTools/pygmt/issues/1986](https://github.com/GenericMappingTools/pygmt/issues/1986)) but we haven’t found time to implement it. In other words, if you like, you can help us implement it.
