# Shapefile to gmt (python)

**URL:** <https://forum.generic-mapping-tools.org/t/shapefile-to-gmt-python/834>\
**Category:** PyGMT Q&A\
**Created:** [September 2, 2020, 10:51am UTC](https://forum.generic-mapping-tools.org/t/shapefile-to-gmt-python/834 "2020-09-02T10:51:35Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [September 2, 2020, 10:00pm UTC](https://forum.generic-mapping-tools.org/t/shapefile-to-gmt-python/834/21 "2020-09-02T22:00:24Z")

</div>

The answer depends a lot on how the ‘lines’ in your shapefile are stored as, are they single linestrings, or multilinestrings? Or are they stored as a feature collection? Might be best if you can provide a sample of your ‘fault.shp’ file (including the .shx and .dbf files) so we can examine it.

That said, what I usually do is to load the shapefile using [geopandas](https://geopandas.org/) first, convert the ‘lines’ to a numpy array of x and y coordinates, and have PyGMT plot that. The code below should help to get you started:

```python
import geopandas as gpd
import pygmt

# Load data from shapefile and convert to numpy array
gdf = gpd.read_file(filename="fault.shp")
linestrings = [geom for geom in gdf.geometry]

# Plot in PyGMT
fig = pygmt.Figure()
for line in linestrings:
    x, y = line.coords.xy
    fig.plot(x=x, y=y, pen="thin")
fig.show()

```

---

_[View the full topic](https://forum.generic-mapping-tools.org/t/shapefile-to-gmt-python/834)._
