# Density plot to earthquake

**URL:** <https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725>\
**Category:** Q&A\
**Created:** [March 3, 2023, 1:22pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725 "2023-03-03T13:22:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 3, 2023, 1:22pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/1 "2023-03-03T13:22:52Z")

</div>

![Density-of-earthquake-magnitudes-colour-scale-with-time-for-the-merged-catalogue_W640](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a071962055e971aa4e3aad7cc9b0d82e10ef9d43.jpeg)

Hello everyone,  
what is a command on the script that i can use to have this result?  
I want to plot a density plot to earthquake and time o for depth, for example.  
Thank you for answers.

---

<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:** [March 3, 2023, 3:01pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/2 "2023-03-03T15:01:01Z")

</div>

Hi Anna

It depens on how do you have your data. If its a table then you could use:

`gmt blockmean data_table -Sn -C -I$res > tmp_Heatmap.xyz`

Here I made a density map (or heatmap) (instead of a profile). The idea is the same.

> <https://github.com/Esteban82/FCEN-2022/blob/main/1_Ejercicios/08F_Heatmap/34_Heatmap.sh>

---

<div class="post-metadata">

**Author:** ![jaltekruse](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jaltekruse/32/1607_2.png) [@jaltekruse](https://forum.generic-mapping-tools.org/u/jaltekruse)\
**Post date:** [March 3, 2023, 4:28pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/3 "2023-03-03T16:28:47Z")

</div>

I’ve been checking out @PlanetGus’s nice [heatmap showcase demo](https://flint.soest.hawaii.edu/t/how-to-create-a-heatmap/1478) that uses `xyz2grid -An` to get the event counts in each grid cell. In the discussion, `gmtbinstats` is another recommended module.

---

<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:** [March 3, 2023, 5:21pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/4 "2023-03-03T17:21:01Z")

</div>

Yes, it seems that PlanetGus solution is better. It makes the grid directly.

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 4, 2023, 2:52pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/5 "2023-03-04T14:52:45Z")

</div>

thanks you!  
i will try this solution.

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 6, 2023, 10:38am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/6 "2023-03-06T10:38:37Z")

</div>

[gmt\_example.txt](https://forum.generic-mapping-tools.org/uploads/short-url/a3MIhvk5rmdPbpQLKfKib3FMww3.txt) (352 Bytes)

this is a example file that i try to use to do a density plot, but it does not work.

i delete other column, for example depth,time.

the coast disappeared. What cant i do? i try to blockmean ecc… and for the exaple of @PlanetGus but i dont understand the second file that you give in gmt match.

---

<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:** [March 6, 2023, 11:44am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/7 "2023-03-06T11:44:50Z")

</div>

It is hard to know without your code or map.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 6, 2023, 12:45pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/8 "2023-03-06T12:45:37Z")

</div>

Please read

> [@Forum tips & tricks: create a good post](https://flint.soest.hawaii.edu/t/forum-tips-tricks-create-a-good-post/2585):
>
> To attract the best answers, make your post easy to read and nice to look at. Follow these points to make it easier to help you and more likely you’ll get a prompt, useful answer. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of something generic like “help me with plotting”. Make use of tags and categories (you can edit those and the title after posting). These will make it more likely that your question will be seen by the peo…

---

<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:** [March 6, 2023, 12:56pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/9 "2023-03-06T12:56:49Z")

</div>

> [@annafiglioli](#):
>
> i dont understand the second file that you give in gmt match

Are you referring to

> [@How to create a heatmap](https://flint.soest.hawaii.edu/t/how-to-create-a-heatmap/1478/1):
>
> `gmt math basin.txt -C0 360 ADD = gbas.txt`

The file `basin.txt` contains the lon/lat coordinates of the Great Basin boundaries in -180(°W)/+180(°E) format. I wanted them in 0/360° format, and I lazily simply added 360 to shift the negative (west) longitudinal coordinates into positive ones (east). But this only works because my values are all west.

At any rate, it’s an optional step that doesn’t concern you much for your case.

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 6, 2023, 1:42pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/10 "2023-03-06T13:42:35Z")

</div>

```auto
gmt begin prova png  

    gmt makecpt -Cjet -T0/400.000/10
    gmt coast -R11.50894/15.77485/35.27988/39.50000 -Wthin -B -JM5i -Gbeige -Slightblue -I1
    gmt binstats C:\programs\prova_sicilia_.txt -Gsicilia.nc -I10km -Tr -Cn -R11.50894/15.77485/35.27988/39.50000
    gmt grdimage sicilia.nc -B -C -R11.50894/15.77485/35.27988/39.50000

gmt end show

```

 ![prova](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/02c2a5d324ca22e3bb42b49b888cc1cf586d87b2.png)  
this is my result.  
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’  
i want only the distribution of points and the density of points in area, if it in the maps or graphs. this case i try in the maps.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 6, 2023, 5:29pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/11 "2023-03-06T17:29:48Z")

</div>

This is like in bed. If you put the pillow on top of the mobile phone you won’t see it. For that you have to put the mobile on top of the pillow. Here the pillow is the `grdimage` and the mobile the `coast` commands.

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 7, 2023, 8:37am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/12 "2023-03-07T08:37:44Z")

</div>

ok now the coast do not disappear.

This is my now code

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’  
gmt begin prova png

gmt xyz2grd C:\programs\prova\_sicilia\_.txt -Gsicilia.ei+n -I5km -R11.50894/15.77485/35.27988/39.50000 -fg

```
gmt makecpt -Cjet -T0/400.000/10

gmt grdimage sicilia.ei -B -C -R11.50894/15.77485/35.27988/39.50000

```

gmt coast -B -R11.50894/15.77485/35.27988/39.50000 -Wthin

gmt end show  
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

the gmt ask me to give a compatible -R and -I in xyz2grd, why?  
now i see only blue in my map.

---

<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:** [March 7, 2023, 9:19am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/13 "2023-03-07T09:19:32Z")

</div>

You may wish to get a grasp of what GMT distance units are expected from the [docs](https://docs.generic-mapping-tools.org/dev/cookbook/features.html#gmt-units). There is no “km” for instance, Since **xyz2grd** reformats a table into an equidistant grid it is expected that the increment fits inside the given region - hence your messages. Asking for a 5km spacing means GMT will convert that into an equivalent degree interval for your longitude and latitudes and it is unlikely to match exactly.

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 7, 2023, 9:42am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/14 "2023-03-07T09:42:54Z")

</div>

ok thaks.  
now work.  
but now do not work the makecpt in grdimage.  
I receive a map with only color blu. I try to put -Cjet directly in grdimage and work.  
But i want to modify the parameters independently that grdimage.

---

<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:** [March 7, 2023, 12:07pm UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/15 "2023-03-07T12:07:26Z")

</div>

You might want to use an output file with `makecpt`

```auto
makecpt [...] > mypalette.cpt
[...]
grdimage [...] -Cmypalette.cpt

```

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 8, 2023, 8:16am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/16 "2023-03-08T08:16:11Z")

</div>

ok thanks. but i receive the error.  
Thanks, but other than that, I didn’t find what I was looking for.  
if you want I’ll give you my data resized for a moment.

I simply wanted to make a density plot like the example above. and then I already ask myself the problem of creating grid images, for example showing the number of counts.

This is the given example I have.  
Longitude, latitude, depth, magnitude, time.

I would like to use your code, also because once the solution is found I can apply it to all parts of the world that may interest me.[prova\_GMT.txt](https://forum.generic-mapping-tools.org/uploads/short-url/zcNABgRncnPwrgiaGLEmXrWmRZj.txt) (21.2 KB)

---

<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:** [March 8, 2023, 10:26am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/17 "2023-03-08T10:26:33Z")

</div>

See the [updated showcase](https://flint.soest.hawaii.edu/t/how-to-create-a-heatmap/1478/11) 🙂

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 8, 2023, 10:41am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/18 "2023-03-08T10:41:45Z")

</div>

really thanks to help me!

---

<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:** [March 8, 2023, 10:49am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/19 "2023-03-08T10:49:18Z")

</div>

My pleasure,  
Now you can exercise by changing `-Cn` by `-Cu` and see if you get the maximum depth instead of the count of earthquakes. Or `-Cs` to look at where the highest variability is.

More interesting exercise for you would be to transform the lower panel (lon x depth) into a heatmap too…

---

<div class="post-metadata">

**Author:** ![annafiglioli](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@annafiglioli](https://forum.generic-mapping-tools.org/u/annafiglioli)\
**Post date:** [March 8, 2023, 10:56am UTC](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725/20 "2023-03-08T10:56:44Z")

</div>

I receive this error… i use the same code.  
grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline  
grdimage (gmt\_api.c:5185(gmtapi\_import\_grid)): Grid x increment \<= 0.0  
[Session gmt (0)]: Error returned from GMT API: GMT\_RUNTIME\_ERROR (79)  
[Session gmt (0)]: Error returned from GMT API: GMT\_RUNTIME\_ERROR (79)  
[Session gmt (0)]: Error returned from GMT API: GMT\_RUNTIME\_ERROR (79)

[Next page](https://forum.generic-mapping-tools.org/t/density-plot-to-earthquake/3725.md?page=2)
