# Plot FocalMechanims

**URL:** <https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266>\
**Category:** PyGMT Q&A\
**Created:** [November 5, 2021, 2:34pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266 "2021-11-05T14:34:24Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [November 5, 2021, 2:34pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/1 "2021-11-05T14:34:24Z")

</div>

Dear all,  
I was trying to plot focal mechanism solutions based on aki format, however I got the following error:

```
GMTInvalidInput: Arguments in short-form (C) and long-form (offset) can't coexist

```

My input file is attached [gCMT\_sols.dat](https://forum.generic-mapping-tools.org/uploads/short-url/7qiUorz7nPIMtc1szDem40XtDhj.dat) (762 Bytes)

The code I am using to plot the focal mechanism is:

```
df_focal_mecha = pd.read_csv('gCMT_sols.dat', sep='\s+')

df_focal_mecha.head()

fig.meca(
    spec=df_focal_mecha,
    convention = 'aki',
    scale="1.0c",
    C=True,
    offset = True,
    )           

```

Dis I do a mistake over the input format?  
Thanks in advance  
Tonino

---

<div class="post-metadata">

**Author:** ![mgrund](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mgrund/32/139_2.png) [@mgrund](https://forum.generic-mapping-tools.org/u/mgrund)\
**Post date:** [November 5, 2021, 3:24pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/2 "2021-11-05T15:24:55Z")

</div>

First of all you need to define a cpt before using `C = True`:

```auto
import pygmt

fig = pygmt.Figure()
pygmt.makecpt(cmap= "roma")

fig.meca(
    spec = 'gCMT_sols.dat',
    convention = 'aki',
    scale = "1.0c",
    offset = True,
    frame = True,
    C = True)  

fig.show()

```

which gives you the following:

 ![index](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/0900e2ccb83fd9669ddf93fc1683aeb7e32c03e1.png)

However, I assume you want to color your focal mechanisms based on depth or something like that?

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [November 5, 2021, 3:42pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/3 "2021-11-05T15:42:15Z")

</div>

Dear @mgrund,  
Thank you for the answer. Yes I’d like to color according to depth. Should I create a color map too rigth?  
Tonino

---

<div class="post-metadata">

**Author:** ![mgrund](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mgrund/32/139_2.png) [@mgrund](https://forum.generic-mapping-tools.org/u/mgrund)\
**Post date:** [November 5, 2021, 5:25pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/4 "2021-11-05T17:25:30Z")

</div>

In principle, yes. Depending on how your input data is formatted, depth should be in the third column. However, your data has 9 columns and the filename contains “gCMT”, on the other side you set convention to `'aki'`. Is your data in the right format?

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [November 5, 2021, 6:36pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/5 "2021-11-05T18:36:15Z")

</div>

@mgrund, about the input file, the data comes from GCMT for that reason I named gCMT.  
The input is “sorted” like the AKI format, however the last two columns are offset where I’d like to plot the beach-balls (same as GMT input), however I am not able to plot with offset the beach-balls.

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [November 5, 2021, 8:05pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/6 "2021-11-05T20:05:48Z")

</div>

@mgrund, I just updated the version of PyGMT to newest and it’s running smooth the offset for beach-balls, thank you, stay safe and best regards  
Tonino

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [December 3, 2021, 12:02am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/7 "2021-12-03T00:02:46Z")

</div>

Dear @mgrund,  
It worked, here I paste the code, just in case anyone need it.

```auto
pygmt.makecpt(cmap = 'hot',
                  series = [1,70,3])  

fig.meca(
    spec='Nieto_sols.dat',
    convention = 'aki',
    scale="0.7c",
    offset = True,
    frame = True,
    C = True
    )           

fig.colorbar(frame=["x+lFM-Depth", "y+lkm"], position="JMR+o0.5c/0c+w8c")

```

Stay safe and best regards,  
Tonino

 ![Map-Nieto-Focal-Mechanism](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/23d9ba200bd3d76ad33f0d337e6f7096470a165b.png)

---

<div class="post-metadata">

**Author:** ![jtownendVUW](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jtownendvuw/32/1572_2.png) [@jtownendVUW](https://forum.generic-mapping-tools.org/u/jtownendVUW)\
**Post date:** [December 3, 2021, 3:52am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/8 "2021-12-03T03:52:48Z")

</div>

Dear @tonino13,

Thank you very much for posting your code for coloring focal mechanisms by depth. I hadn’t updated PyGMT to v0.5.0 but have now done that and this seems to have been the final step required to crack the problem. Like you, I think, I also found I had to write my data frame out as a tab-separated file and then read it in again, instead of passing it directly to meca.

Thanks again and best wishes from Wellington,  
John T.

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 18, 2022, 7:52pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/9 "2022-04-18T19:52:45Z")

</div>

The GMT must be installed to work with pygmt

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 18, 2022, 7:56pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/10 "2022-04-18T19:56:23Z")

</div>

i cant still plotting offset for beachballs???  
data input coulmn is lon lat depth strike dip slip mag plot\_lon plot\_lat with txt format  
whats problem  
and i installed last version pygmt 7.0

---

<div class="post-metadata">

**Author:** ![tonino13](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/tonino13/32/1440_2.png) [@tonino13](https://forum.generic-mapping-tools.org/u/tonino13)\
**Post date:** [April 19, 2022, 3:16am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/11 "2022-04-19T03:16:05Z")

</div>

Hi @kami, your input data file must have the following format:

> Lon Lat Depth Strike Dip Rake Mag OffsetLon OffsetLat

For exmaple, in a txt file you should have:

`-65.700 -17.108 4.6 114.78 39.78 45.35 4.4 -65.516 -17.148`

The last two columns (OffsetLon and OffsetLat) are the place where you want to plot the Focal Mechanism.

I hope this help, stay safe,  
Tonino

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 19, 2022, 8:28am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/12 "2022-04-19T08:28:25Z")

</div>

Dear @tonino13 thanks for reply. see my input file What do you think?

 ![Screenshot from 2022-04-12 02-29-02](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/7/7e776b2934b8cd0ea0fc981dc8436e3e59e1fa6e.png)

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 19, 2022, 8:35am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/13 "2022-04-19T08:35:46Z")

</div>

I think, input file reads all the columns in just one column

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 19, 2022, 7:40pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/14 "2022-04-19T19:40:58Z")

</div>

my code with its error is:

> > ​data=pd.read\_csv(“focmec.txt”)  
> > lon lat depth strike dip rake mag p\_lon p\_lat  
> > 0 53.48 36.07 12.2 220.7 52.3 170.4 4.6 53.1 36.2  
> > 1 55.09 36.98 16.1 316.6 64.7 -190.1 5.2 55.1 37.2  
> > 2 53.01 36.67 25.1 137.6 28.5 91.0 4.7 54.2 35.9
> > 
> > > fig.meca(spec=data, convention=“aki”, scale=“0.7c”,plot\_longitude=True, plot\_latitude=True, offset=True)  
> > > raise GMTError(  
> > > pygmt.exceptions.GMTError: Parameters in spec dictionary do not match known conventions.

---

<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:** [April 19, 2022, 7:53pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/15 "2022-04-19T19:53:20Z")

</div>

if the leading 0, 1, 2 is in your data file then you are off by one column - you gotta get rid of those running numbers.

---

<div class="post-metadata">

**Author:** ![kami](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kami/32/2169_2.png) [@kami](https://forum.generic-mapping-tools.org/u/kami)\
**Post date:** [April 20, 2022, 8:18am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/16 "2022-04-20T08:18:39Z")

</div>

Dear @pwessel your comment is true. i change input data to this

> > data=pd.read\_csv(“focmec.csv”, header=None,delimiter=“\s+”)
> > 
> > > data  
> > > 0 1 2 3 4 5 6 7 8  
> > > 0 53.48 36.07 12.2 220.7 52.3 170.4 4.6 53.1 36.2  
> > > 1 55.09 36.98 16.1 316.6 64.7 -190.1 5.2 55.1 37.2  
> > > 2 53.01 36.67 25.1 137.6 28.5 91.0 4.7 54.2 35.9  
> > > but it doesnt still work.  
> > > If possible you give me a csv file that you with it plotted offset and i will try with it.

---

<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:** [April 21, 2022, 10:54am UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/17 "2022-04-21T10:54:12Z")

</div>

Sorry, I do not use pyGMT so I do not know if the read\_csv command inserts those running numbers 0 1 2 etc or if they are in your data file. Maybe @seisman can suggest something?

---

<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:** [April 27, 2022, 11:25pm UTC](https://forum.generic-mapping-tools.org/t/plot-focalmechanims/2266/18 "2022-04-27T23:25:23Z")

</div>

@kami, can you reply with the first few lines from `focmec.csv` so that we can see what the raw data look like?
