# Shading altering color of plot?

**URL:** <https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918>\
**Category:** PyGMT Q&A\
**Created:** [May 13, 2022, 3:21am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918 "2022-05-13T03:21:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdtanker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mdtanker/32/1184_2.png) [@mdtanker](https://forum.generic-mapping-tools.org/u/mdtanker)\
**Post date:** [May 13, 2022, 3:21am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/1 "2022-05-13T03:21:46Z")

</div>

I am trying to apply shading to a topography grid, which has the foreground color set to white (topography \> -300m). The upper right portion of the first plot shows that this is working correctly. When I apply shading within grdimage, either with default (shading=“+d”) or a grdimage call (shading=“grdgradient+a45+ne.5”) the shaded parts of the figure which should be white became a reddish color. Is there some parameter I’m missing that only changes the brightness of the color, and not the color itself? Thanks!

Below is my code for create the cmap and for plot the grid.

```python
with pygmt.config(COLOR_FOREGROUND='white'):
    pygmt.grd2cpt(grid = '../data/results/Bedmachine_bed_5k_wgs.nc', cmap = 'batlowW',
                limit = '-900/-300', nlevels=7,
                output = '../data/plotting/RE_bathymetry.cpt')

    fig.grdimage(projection=fig_proj,
                 region=fig_reg,
                 grid='../data/results/Bedmachine_bed_5k_wgs.nc',
                 cmap='../data/plotting/RE_bathymetry.cpt',
                 shading="+d", #"grdgradient+a45+ne.5",
                 dpi=500,
                 frame = ["nwse", "xf100000", "yf100000", "g0"])

```

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/7/7f5d0733598856de07fd99ded045b5a65181fd71.jpeg)  
 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/7/7cfa57e6030eeb6eaf346952308d0a7b497f70d4.jpeg)

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [May 13, 2022, 8:47am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/2 "2022-05-13T08:47:00Z")

</div>

As far as I can understand, there is quite a lot of topographic features above -300 meters so shaded relief is created there using your palette colors. This results in white highlights and reddish shades, while `grdmage` without shading just plots everything above -300 m as white.

You probably need to mask everything above -300 m to keep the shaded relief below -300 m and make everything plain white above. E.g. by clipping shaded relief to the -300 m contour from the grid. Or by plotting grdimage without shading above -300 as white and below as 100% transparent on top of the shaded relief.

---

<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:** [May 13, 2022, 10:37am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/3 "2022-05-13T10:37:24Z")

</div>

Also, I think batlow has a default foreground color, based on the CPT file:

**F 250/204/250**

so that is probably used for any value above your range.

---

<div class="post-metadata">

**Author:** ![mdtanker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mdtanker/32/1184_2.png) [@mdtanker](https://forum.generic-mapping-tools.org/u/mdtanker)\
**Post date:** [May 15, 2022, 8:16pm UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/4 "2022-05-15T20:16:57Z")

</div>

Ok thanks for those answers. If I want to keep the area above -300m shaded, but have the shading be gray instead of pink, is there a way to do that? I thought changing the CPT foreground color to white would have fixed that?

---

<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:** [May 16, 2022, 12:11am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/5 "2022-05-16T00:11:24Z")

</div>

Hi Matt, glad to see your paper coming all nicely, hope you’re doing well in Wellington 😄

Anyways, extending on @mkononets’s answer, you could try to shade grid cells \<-300m using [`grdclip`](https://www.pygmt.org/v0.6.1/api/generated/pygmt.grdclip.html) to turn elevation values \>=-300m to NaN. Specifically, something like

```python
grid_clipped = pygmt.grdclip(
    grid="../data/results/Bedmachine_bed_5k_wgs.nc",
    above=[-300, "NaN"],
)
fig.grdimage(
    grid=grid_clipped,
    shading="+d",
    ...
)

```

Haven’t tested this, and not sure if the NaN string works properly but give that a go first. You might also need to set [`COLOR_BACKGROUND`](https://docs.generic-mapping-tools.org/6.3/gmt.conf.html#term-COLOR_BACKGROUND) or some other config to white.

Similarly, if you want to shade areas above -300m with gray, you could make another `grdclip` that sets values below -300m to NaN, and do another `grdimage` call but use a `gray` colormap instead.

Alternatively, you could try to figure out how to combine two colormaps into one CPT file using [https://docs.generic-mapping-tools.org/6.3/makecpt.html](https://docs.generic-mapping-tools.org/6.3/makecpt.html). Something like:

```bash
gmt makecpt -CbatlowW -T-900/-300/100 -N > RE_bathymetry.cpt
gmt makecpt -Cgray -T-300/-100/100 >> RE_bathymetry.cpt

```

which would produce a CPT file like:

```bash
-900	14.25/55.25/94.25	-800	14.25/55.25/94.25	L
-800	31.75/94.75/97.25	-700	31.75/94.75/97.25	L
-700	89.5/122.25/72.75	-600	89.5/122.25/72.75	L
-600	168.5/149.75/53.75	-500	168.5/149.75/53.75	L
-500	231.25/171.25/132.5	-400	231.25/171.25/132.5	L
-400	255/226.75/225.75	-300	255/226.75/225.75	B
-300	gray25	-200	gray25	L
-200	gray75	-100	gray75	B
B	black
F	white
N	128

```

and then you would just need to use one `grdimage` call but pass in this `RE_bathymetry.cpt` instead.

---

<div class="post-metadata">

**Author:** ![mdtanker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mdtanker/32/1184_2.png) [@mdtanker](https://forum.generic-mapping-tools.org/u/mdtanker)\
**Post date:** [May 16, 2022, 12:53am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/6 "2022-05-16T00:53:08Z")

</div>

Hey @weiji14! Yes just submitting the final proofs for the paper now, but it’s already online 🙂

We’re missing you here in the ARC!

Thanks for the help. The clipping worked perfectly. Here’s the updated figure.

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

---

<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:** [May 16, 2022, 2:01am UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/7 "2022-05-16T02:01:19Z")

</div>

Haha cool, glad you got it to work. You must have spent like a year on that figure already! I’m missing Wellington too, especially the wind and ~20°C summers, it’s getting to about 30°C already in Columbus and probably gonna get higher in the coming months. If only the houses were a bit more drafty here 😆

---

<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:** [May 25, 2022, 3:02pm UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/8 "2022-05-25T15:02:16Z")

</div>

By the way, Matt’s paper is out at [https://doi.org/10.1029/2021GL097371](https://doi.org/10.1029/2021GL097371) (open access). Plus all the code is at [GitHub - mdtanker/RIS\_basement\_sediment: Ross Ice Shelf basement depths and sediment thickness · GitHub](https://github.com/mdtanker/RIS_basement_sediment).

[![](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/1/1ca314518a27ac43bebe4a08bb76ead7ebd3edd0.jpeg)](https://github.com/mdtanker/RIS_basement_sediment)

You should definitely showcase this on [External Resources — PyGMT](https://www.pygmt.org/v0.6.1/external_resources.html#examples-from-publications-and-posters) @mdtanker 😉

---

<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:** [May 25, 2022, 3:32pm UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/9 "2022-05-25T15:32:22Z")

</div>

Cool figures, congrats … and a challenge.  
Create a color variable line along the the edges of the figure, with the same color as the pixel edges themselves to do an anti-aliasing effect and hide that less pleasing saw-tooth effect that we see.

---

<div class="post-metadata">

**Author:** ![mdtanker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mdtanker/32/1184_2.png) [@mdtanker](https://forum.generic-mapping-tools.org/u/mdtanker)\
**Post date:** [May 25, 2022, 8:06pm UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/10 "2022-05-25T20:06:25Z")

</div>

@weiji14 Thanks for posting that here 🙂 Lots of help from you along the way! Good idea about adding it to the examples.

Good suggestion @Joaquim, I’ll see if I can figure that out and fix it.

---

<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:** [May 25, 2022, 8:10pm UTC](https://forum.generic-mapping-tools.org/t/shading-altering-color-of-plot/2918/11 "2022-05-25T20:10:49Z")

</div>

Oh, my challenge was not directed specifically to you, but to us all.
