GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Fill positive areas in ploting (add GMT wiggle module) #1114

Closed zhen-dong-zhang closed 3 years ago

zhen-dong-zhang commented 3 years ago

Hi, I'm new to pygmt and wondering how to fill the positive areas in plotting? Please find the figure below for more information: fill Thanks for your attention. Best Regards, Zhendong

welcome[bot] commented 3 years ago

👋 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.

maxrjones commented 3 years ago

It's not included in PyGMT yet but your request sounds similar to GMT's wiggle module. Can you take a look at the documentation for wiggle and let us know if this suites your request? If so, we can convert this into a feature request for a wiggle method in PyGMT. Here's the output from an example in the GMT docs:

wiggle

zhen-dong-zhang commented 3 years ago

Hi Meghan, Thanks a lot for your reply. Yes, it is wiggle plotting, which is very popular in exploration geophysics. I have implemented it by using matplot. But it would be helpful if pygmt can have this function. Best Regards, Zhendong

maxrjones commented 3 years ago

Hi Zhendong, I am glad you found a way to make the plot and agree that this would be a nice function to have in PyGMT! We'll keep the issue open and I will add the GMT module name to the title of your GitHub issue so that developers can find it easier to work on. Best regards, Meghan

zhen-dong-zhang commented 3 years ago

Hi Meghan, Thank you for taking the time and effort in adding the module. I'm looking forward to it. Best Regards, Zhendong

core-man commented 3 years ago

@zhen-dong-zhang you could still use wiggle in PyGMT even though we have wrapped it. See an example below modified from Examples

GMT command line:

gmt math -T-8/6/0.01 -N3/0 -C2 T 3 DIV 2 POW NEG EXP T PI 2 MUL MUL COS MUL 50 MUL = | gmt wiggle -R-10/10/-1/1 -JX15c -BWSne -Bxa2f1 -Bya0.5 -Z10c -DjRM+w100+lnT -T0.5p -Gred+p+n -W0.5p -pdf map

PyGMT call_module method:

import pygmt
from pygmt.clib import Session
import numpy as np

# Create (x, y, z) which is equal to the gmt math above
x = np.arange(-8, 7, 0.1)
y = np.zeros(x.size)
z = 50 * np.exp(-(x/3)**2) * np.cos(2*np.pi*x)

fig = pygmt.Figure()
fig.basemap(region=[-10, 10, -1, 1], projection="X15c", frame=["WSne", "xa2f1", "ya0.5"])
with pygmt.helpers.GMTTempFile() as temp_file:
    np.savetxt(temp_file.name, np.column_stack((x, y, z)))
    with Session() as session:
        session.call_module("wiggle", "{} -Z10c -DjRM+w100+lnT -T0.5p -Gred+p+n -W0.5p".format(temp_file.name))
fig.show()

BTW, I am going to wrap wiggle next week if no other contributors try it during these 2-3 days.