# Bug in grdimage?

**URL:** https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217
**Category:** Q&A
**Created:** [October 23, 2021, 3:19am UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217 "2021-10-23T03:19:14Z")
**Posts on this page:** 6
**Page:** 1

<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: [October 23, 2021, 3:19am UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/1 "2021-10-23T03:19:14Z")

</div>

I create an slope grid and then plotted it.

I don’t understand why in the image below I get those white areas. They disappear if I remove `-C` from `grdimage` (or if I use a cartesian projection `-JX`). Is it a bug?

 ![BUG_Slope](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/0/01052d50c3c68953d9ad865738991db8e19d127f.jpeg)

```
#!/usr/bin/env bash

CUT=tmp_$title.nc

gmt begin BUG_Slope png E150
	gmt grdcut @earth_relief_30s -G$CUT -R-69/-64/-35/-33
	gmt grdgradient $CUT -D -S$CUT -fg
	gmt grdmath $CUT ATAN R2D = $CUT -fg
	gmt grdinfo $CUT

	gmt makecpt -T0/25 -I
	gmt grdimage $CUT -C -JM15c -Baf
	gmt grdimage $CUT -JM15c -Bf -Y7.5c
# gmt grdimage $CUT -JX15c -Bf -Y7.5c

	gmt colorbar -DJRM+o0.3/0+e -C -Ba+l"Slope @."
gmt end
rm $CUT

```

---

<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: [October 23, 2021, 4:22am UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/2 "2021-10-23T04:22:47Z")

</div>

See -n+c. Basically, your geographic grid with positive slopes needs to be resampled by a (by default) bicubic interpolator which may produce values outside the range of the original grid (small negative values which ends up being colored white). The +c modifier truncates the grid to the original min/max limits. Or use -nl for bilinear which will not exceed those limits.

---

<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: [October 25, 2021, 12:23pm UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/3 "2021-10-25T12:23:51Z")

</div>

It works with -n+c. Now I don’t understand why I have to add -n+c when I add -C. There is no need to do that when I don’t use -C:

```auto
	gmt grdimage $CUT -C -JM15c -n+c
	gmt grdimage $CUT -JM15c 

```

---

<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: [October 25, 2021, 5:08pm UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/4 "2021-10-25T17:08:34Z")

</div>

With -C you get the CPT you created from 0-25 and without perhaps you get a stretched default CPT?

---

<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: [October 25, 2021, 5:20pm UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/5 "2021-10-25T17:20:45Z")

</div>

Yes, it seems so. But I didn’t expect that behavior from adding -C.

---

<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: [October 25, 2021, 6:41pm UTC](https://forum.generic-mapping-tools.org/t/bug-in-grdimage/2217/6 "2021-10-25T18:41:38Z")

</div>

Maybe I can write something on the grdimage doc page, but basically:

1. Once you run makecpt and create a specific CPT its domain will be honored exactly since you gave -C to use it. So the resampling pushes outside and you get the back/foreground colors (white)
2. If you give no -C then a default CPT is used (depending on the data) and it is auto-stretched to whatever the range is. It may even have a different back/foreground setting.
3. If you give -C with a master table then it should be the same as 2 but different colors.
