pygmt icon indicating copy to clipboard operation
pygmt copied to clipboard

Is that possible to fill the space between the contour lines using hachure patterns? Or use them in grdimage?

Open phalucy opened this issue 1 year ago • 5 comments

Description of the desired feature

In many geo-related fields, we need to plot spatial distributions of composite values or trends together with their significant levels. Many papers have those kinds of maps by showing the levels with dots/hatchure patterns. However, I don't know there is a way to reproduce those figures with hatched significant fields in GMT. Is there any way to plot some patterns/dots/lines over the significant values?

One potential way may be creating a grd file by replacing insignificant values with NaNs. Then, I could use grdimage to plot it using cmap, which contains hachure patterns instead of normal colors. But for now, I don't know how to do so, because hacure patterns only works when 'fill' or '-G' function is available.

By the way, the GMT example 16 (https://docs.generic-mapping-tools.org/dev/gallery/ex16.html) showed a way to use hatched cpt and grdview, but it is not 'elegent' way because we need to edit the cpt file manually. I think it could be possible to include such function inside the codes of GMT/PyGMT.

Are you willing to help implement and maintain this feature?

No

phalucy avatar May 18 '24 16:05 phalucy

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

welcome[bot] avatar May 18 '24 16:05 welcome[bot]

Many papers have those kinds of maps by showing the levels with dots/hatchure patterns.

Can you please show some examples so that we can understand the feature request better?

seisman avatar May 19 '24 07:05 seisman

Many papers have those kinds of maps by showing the levels with dots/hatchure patterns.

Can you please show some examples so that we can understand the feature request better?

Hi, thanks for reply.

Please find the example figures in the following paper: https://www.nature.com/articles/s41467-022-31676-8 (see Figs. 1-3) I think the hatching patterns in those figures may be done by contourf function in matplotlib (https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_hatching.html) or contour effects in NCL (https://www.ncl.ucar.edu/Applications/coneff.shtml; see the example [coneff_13.ncl]).

phalucy avatar May 19 '24 14:05 phalucy

It seems a nice feature but may be not easy to implement.

seisman avatar May 20 '24 15:05 seisman

Maybe a first step would be to allow patterns when setting up a custom colormap. Probably, this is something that has to be implemented directly in GMT.

import pygmt

# -----------------------------------------------------------------------------
# (I) cmap with colors - allowed
fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -1, 1], projection="X10c/2c", frame=0)

pygmt.makecpt(cmap="lightorange,orange,red,darkred", series=[0, 4, 1])
fig.colorbar(cmap=True, position="jMC+h", frame=True)

fig.show()

# %%
# -----------------------------------------------------------------------------
# (II) cmap with pattern - not available
# GMTCLibError: Module 'makecpt' failed with status code 8:
# makecpt [ERROR]: Badly formatted color entry: +p8

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -1, 1], projection="X10c/2c", frame=0)

pygmt.makecpt(cmap="p8,p17,p15,p25", series=[0, 4, 1])
fig.colorbar(cmap=True, position="jMC+h", frame=True)

fig.show()

yvonnefroehlich avatar May 21 '24 06:05 yvonnefroehlich