Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency of colormap does not apply to color-coding for using Figure.grdimage #3629

Open
yvonnefroehlich opened this issue Nov 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@yvonnefroehlich
Copy link
Member

Description of the problem

It's possible to add transparency directly to a colormap while creating it via pygmt.makecpt.

When using this colormap for plotting data points with color-coding via Figure.plot, this transparency is considered, but when plotting a grid with color-coding via Figure.grdimage it is ignored. A workaround is specifying the transparency parameter (with the same value) again for Figure.grdimage.

(I) data points (pandas.DataFrame) via Figure.plot (II) grid (Xarray.DataArray) via Figure.grdimage
cmap_transp_datapoints cmap_transp_grid

Minimal Complete Verifiable Example

# (I) Plotting data points with color-coding
import pygmt

df = pygmt.datasets.load_sample_data(name="japan_quakes")

fig = pygmt.Figure()
fig.basemap(region=[135, 150, 35, 50], projection="M10c", frame=True)

pygmt.makecpt(cmap="viridis", series=[0, 600], transparency=50)
fig.plot(
    x=df.longitude,
    y=df.latitude,
    size=[0.5] * len(df),
    fill=df.depth_km,
    cmap=True,
    style="cc",
)
fig.colorbar(frame=True)

fig.show()

# -----------------------------------------------------------------
# (II) Plotting a grid with color-coding
import pygmt

grid = pygmt.datasets.load_earth_relief()

fig = pygmt.Figure()
fig.basemap(region=[-10, 10, -10, 10], projection="M10c", frame=True)

pygmt.makecpt(cmap="oleron", series=[-1000, 500], transparency=50)
fig.grdimage(grid=grid, cmap=True)
fig.colorbar(frame=True)

fig.show()

Full error message

Not applicable.

System information

import pygmt; pygmt.show_versions()
PyGMT information:
  version: v0.13.0
System information:
  python: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:20:11) [MSC v.1938 64 bit (AMD64)]
  executable: C:\ProgramData\Anaconda3\envs\pygmt_env_dev_650\python.exe
  machine: Windows-10-10.0.19045-SP0
Dependency information:
  numpy: 1.26.4
  pandas: 2.2.2
  xarray: 2024.3.0
  netCDF4: 1.6.5
  packaging: 24.0
  contextily: 1.6.0
  geopandas: 0.14.3
  IPython: 8.22.2
  rioxarray: 0.15.4
  gdal: 3.8.2
  ghostscript: 10.03.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: C:/Program Files (x86)/gmt6/share
  plugin dir: C:/ProgramData/Anaconda3/envs/pygmt_env_dev_650/Library/bin/gmt_plugins
  library path: C:/ProgramData/Anaconda3/envs/pygmt_env_dev_650/Library/bin/gmt.dll
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0
@yvonnefroehlich yvonnefroehlich added the bug Something isn't working label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant