# PyGMT: Plotting Holes In Polygons?

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-plotting-holes-in-polygons/1822>\
**Category:** PyGMT Q&A\
**Created:** [June 23, 2021, 5:11pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-plotting-holes-in-polygons/1822 "2021-06-23T17:11:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazardgoat](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/hazardgoat/32/1354_2.png) [@hazardgoat](https://forum.generic-mapping-tools.org/u/hazardgoat)\
**Post date:** [June 23, 2021, 5:11pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-plotting-holes-in-polygons/1822/1 "2021-06-23T17:11:57Z")

</div>

Hello again! After successfully plotting and coloring a large number of polygons as per my [previous post](https://flint.soest.hawaii.edu/t/pygmt-coloring-polygons-from-a-converted-kml-file/1798/7), I’ve discovered that many of the polygons are being plotted over by other polygons. I suspect that this may be due to PyGMT not respecting the holes? From what I’ve read, it’s been [suggested](https://gmt.soest.hawaii.edu/boards/1/topics/5298) to mark the holes manually. However, I have far to many polygons to correct them by hand. Is there a way to make PyGMT plot the polygons as I wish it to?

My code for plotting the polygons:

```
import geopandas as gpd
import pygmt
import pandas as pd
import fiona
import os

main_dir = r'C:\Users\USER\Desktop\testing'

# Geologic bed polygons gmt file path
polyData = os.path.join(main_dir,'Data', 'GMC_geo_poly.gmt')

# Geologic bed cpt file path
polyColor = os.path.join(main_dir,'Data', 'geo_poly_color.cpt')

# Map save file path
saveName = os.path.join(main_dir, 'Results', 'geologic_map.png')

# Parameters
region = [-125, -122, 38, 40]

fig = pygmt.Figure()

fig.basemap(
    region = region,
    projection = 'M6i',
    frame = 'f'
    )

# plots the polygons from the gmt file
fig.plot(
    data = polyData,
    pen="0.1p,black,-", # set outline colour
    cmap = polyColor,
    color = '+z',
    #verbose=True,
    close=True, # force close polygons
    aspatial='Z=Name',
    transparency = 50
    )
    
fig.coast(
    shorelines = '0.1p,black',
    resolution = 'h',
    water = 'lightskyblue2',
    #transparency = 50,
    )

# saves a copy of the generated figure
fig.savefig(saveName)

```

An example of part of the map with excessive plotting over holes (holes are fainter in color because I set transparency on, as normally they would be completely obscured):

 ![geologic_map](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/d/dc0753c489842c2bdd64abc4cdc24031f3ce6e4f.jpeg)

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [June 23, 2021, 6:11pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-plotting-holes-in-polygons/1822/2 "2021-06-23T18:11:19Z")

</div>

You could try running your polyData through `gmt spatial -Sh` first. See the note here:

> **[kml2gmt — GMT 6.3.0 documentation](https://docs.generic-mapping-tools.org/dev/kml2gmt.html#notes)**

---

<div class="post-metadata">

**Author:** ![hazardgoat](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/hazardgoat/32/1354_2.png) [@hazardgoat](https://forum.generic-mapping-tools.org/u/hazardgoat)\
**Post date:** [June 28, 2021, 6:24am UTC](https://forum.generic-mapping-tools.org/t/pygmt-plotting-holes-in-polygons/1822/4 "2021-06-28T06:24:16Z")

</div>

I eventually figured out how to use gmt spatial -Sh, but it wasn’t able to correct the issue. As it turns out, there is/was data loss when converting the shp file to kml, which is where the problem with the holes was rooted. I ended up simply using QGIS to convert the shp file crs to epsg:4326 and _then_ converting directly to gmt. The correct information about the polygons was preserved and they plotted perfectly.
