Fig.grdimage transparency no longer working

I just upgraded to Python 3.12 … and transparency is no longer working. Here’s a code snippet:

da = pygmt.surface(data=df[[‘x’, ‘y’, ‘z’]], spacing=[gridinc_x, gridinc_y], region=region)
pygmt.makecpt(series=[float(da.min()), float(da.max())], cmap=‘viridis’, transparency=80)
fig.grdimage(grid=da, cmap=True, transparency=80, nan_transparent=True, region=region, projection=projection)

The result is an opaque grid (i.e., equivalent to transparency=0).
Here’s what I’m running with.

PyGMT information:
version: v0.10.0
System information:
python: 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:26:13) [MSC v.1935 64 bit (AMD64)]
Dependency information:
numpy: 1.26.0
pandas: 2.1.1
xarray: 2023.9.0
netCDF4: 1.6.4
packaging: 23.2
contextily: 1.4.0
geopandas: 0.14.0
IPython: 8.16.1
rioxarray: 0.15.0
ghostscript: 10.02.0

I recently also ran into this issue - ghostscript is at fault. I had to downgrade to 9.54 to make it work, as per this example.

1 Like

FYI: GMT 6.5.0 will work well with gs 10.02.0. For GMT 6.4.0 you have to stay with gs 9.54.0.

2 Likes

Thanks to tourmaligned and yvonnefroehlich – downgrading to ghostscript: 9.56.1 works OK for now.

PyGMT information:
version: v0.10.0
System information:
python: 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:26:13) [MSC v.1935 64 bit (AMD64)]
Dependency information:
numpy: 1.26.0
pandas: 2.1.1
xarray: 2023.9.0
netCDF4: 1.6.4
packaging: 23.2
contextily: 1.4.0
geopandas: 0.14.0
IPython: 8.16.1
rioxarray: 0.15.0
ghostscript: 9.56.1
GMT library information:
binary version: 6.4.0

I actually ran into the problem again recently when I upgraded PyGMT to v0.10.0. It tried to use an updated Ghostscript (10.0.02) within the conda environment even though I downgraded the Ghostscript version in Linux.

The solution I found was to specify the Ghostscript that you want to use by putting gs_path and inputting the path towards it in the fig.savefig command. Something like:

fig.savefig(‘savefig.png’,gs_path="/usr/bin/gs")

1 Like

Check your GMT version. If you’re using GMT 6.4.0, then you need gs 9.56.1; if you’re using GMT 6.5.0, then use gs 10.02.1.