Skip to content

Commit 4e4dbbc

Browse files
seismanweiji14
andauthored
Add common alias transparency (-t) to all plotting functions (#614)
-t for transparency. See https://docs.generic-mapping-tools.org/latest/gmt.html#t-full Co-authored-by: Wei Ji <[email protected]>
1 parent f0bd178 commit 4e4dbbc

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

pygmt/base_plotting.py

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use
6868
G="land",
6969
S="water",
7070
U="timestamp",
71+
t="transparency",
7172
)
7273
@kwargs_to_strings(R="sequence")
7374
def coast(self, **kwargs):
@@ -128,6 +129,7 @@ def coast(self, **kwargs):
128129
shorelines : str
129130
``'[level/]pen'``
130131
Draw shorelines [Default is no shorelines]. Append pen attributes.
132+
{t}
131133
132134
"""
133135
kwargs = self._preprocess(**kwargs)
@@ -144,6 +146,7 @@ def coast(self, **kwargs):
144146
F="box",
145147
G="truncate",
146148
W="scale",
149+
t="transparency",
147150
)
148151
@kwargs_to_strings(R="sequence", G="sequence")
149152
def colorbar(self, **kwargs):
@@ -205,6 +208,7 @@ def colorbar(self, **kwargs):
205208
scale : float
206209
Multiply all z-values in the CPT by the provided scale. By default
207210
the CPT is used as is.
211+
{t}
208212
209213
"""
210214
kwargs = self._preprocess(**kwargs)
@@ -225,6 +229,7 @@ def colorbar(self, **kwargs):
225229
U="timestamp",
226230
W="pen",
227231
l="label",
232+
t="transparency",
228233
)
229234
@kwargs_to_strings(R="sequence", L="sequence", A="sequence_plus")
230235
def grdcontour(self, grid, **kwargs):
@@ -281,6 +286,7 @@ def grdcontour(self, grid, **kwargs):
281286
to be of the format [*annotcontlabel*][/*contlabel*]. If either
282287
label contains a slash (/) character then use ``|`` as the
283288
separator for the two labels instead.
289+
{t}
284290
"""
285291
kwargs = self._preprocess(**kwargs)
286292
kind = data_kind(grid, None, None)
@@ -296,7 +302,15 @@ def grdcontour(self, grid, **kwargs):
296302
lib.call_module("grdcontour", arg_str)
297303

298304
@fmt_docstring
299-
@use_alias(R="region", J="projection", W="pen", B="frame", I="shading", C="cmap")
305+
@use_alias(
306+
R="region",
307+
J="projection",
308+
W="pen",
309+
B="frame",
310+
I="shading",
311+
C="cmap",
312+
t="transparency",
313+
)
300314
@kwargs_to_strings(R="sequence")
301315
def grdimage(self, grid, **kwargs):
302316
"""
@@ -312,6 +326,7 @@ def grdimage(self, grid, **kwargs):
312326
----------
313327
grid : str or xarray.DataArray
314328
The file name of the input grid or the grid loaded as a DataArray.
329+
{t}
315330
316331
"""
317332
kwargs = self._preprocess(**kwargs)
@@ -343,6 +358,7 @@ def grdimage(self, grid, **kwargs):
343358
Wf="facadepen",
344359
p="perspective",
345360
I="shading",
361+
t="transparency",
346362
)
347363
@kwargs_to_strings(R="sequence", p="sequence")
348364
def grdview(self, grid, **kwargs):
@@ -419,6 +435,8 @@ def grdview(self, grid, **kwargs):
419435
intensity, and ambient arguments for that module, or just give
420436
``+d`` to select the default arguments (``+a-45+nt1+m0``).
421437
438+
{t}
439+
422440
"""
423441
kwargs = self._preprocess(**kwargs)
424442
kind = data_kind(grid, None, None)
@@ -458,6 +476,7 @@ def grdview(self, grid, **kwargs):
458476
l="label",
459477
C="cmap",
460478
U="timestamp",
479+
t="transparency",
461480
)
462481
@kwargs_to_strings(R="sequence", i="sequence_comma")
463482
def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
@@ -527,6 +546,8 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
527546
{U}
528547
label : str
529548
Add a legend entry for the symbol or line being plotted.
549+
550+
{t}
530551
"""
531552
kwargs = self._preprocess(**kwargs)
532553

@@ -576,6 +597,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
576597
i="columns",
577598
l="label",
578599
C="levels",
600+
t="transparency",
579601
)
580602
@kwargs_to_strings(R="sequence", i="sequence_comma")
581603
def contour(self, x=None, y=None, z=None, data=None, **kwargs):
@@ -633,6 +655,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
633655
to be of the format [*annotcontlabel*][/*contlabel*]. If either
634656
label contains a slash (/) character then use ``|`` as the
635657
separator for the two labels instead.
658+
{t}
636659
637660
"""
638661
kwargs = self._preprocess(**kwargs)
@@ -663,6 +686,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
663686
Td="rose",
664687
Tm="compass",
665688
U="timestamp",
689+
t="transparency",
666690
)
667691
@kwargs_to_strings(R="sequence")
668692
def basemap(self, **kwargs):
@@ -696,6 +720,7 @@ def basemap(self, **kwargs):
696720
Draws a map magnetic rose on the map at the location defined by the
697721
reference and anchor points
698722
{U}
723+
{t}
699724
700725
"""
701726
kwargs = self._preprocess(**kwargs)
@@ -705,7 +730,14 @@ def basemap(self, **kwargs):
705730
lib.call_module("basemap", build_arg_string(kwargs))
706731

707732
@fmt_docstring
708-
@use_alias(R="region", J="projection", U="timestamp", D="position", F="box")
733+
@use_alias(
734+
R="region",
735+
J="projection",
736+
U="timestamp",
737+
D="position",
738+
F="box",
739+
t="transparency",
740+
)
709741
@kwargs_to_strings(R="sequence")
710742
def logo(self, **kwargs):
711743
"""
@@ -731,6 +763,7 @@ def logo(self, **kwargs):
731763
Without further options, draws a rectangular border around the
732764
GMT logo.
733765
{U}
766+
{t}
734767
735768
"""
736769
kwargs = self._preprocess(**kwargs)
@@ -740,7 +773,14 @@ def logo(self, **kwargs):
740773
lib.call_module("logo", build_arg_string(kwargs))
741774

742775
@fmt_docstring
743-
@use_alias(R="region", J="projection", D="position", F="box", M="monochrome")
776+
@use_alias(
777+
R="region",
778+
J="projection",
779+
D="position",
780+
F="box",
781+
M="monochrome",
782+
t="transparency",
783+
)
744784
@kwargs_to_strings(R="sequence")
745785
def image(self, imagefile, **kwargs):
746786
"""
@@ -774,14 +814,21 @@ def image(self, imagefile, **kwargs):
774814
monochrome : bool
775815
Convert color image to monochrome grayshades using the (television)
776816
YIQ-transformation.
817+
{t}
777818
"""
778819
kwargs = self._preprocess(**kwargs)
779820
with Session() as lib:
780821
arg_str = " ".join([imagefile, build_arg_string(kwargs)])
781822
lib.call_module("image", arg_str)
782823

783824
@fmt_docstring
784-
@use_alias(R="region", J="projection", D="position", F="box")
825+
@use_alias(
826+
R="region",
827+
J="projection",
828+
D="position",
829+
F="box",
830+
t="transparency",
831+
)
785832
@kwargs_to_strings(R="sequence")
786833
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
787834
"""
@@ -816,6 +863,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
816863
rectangular border around the legend using **MAP_FRAME_PEN**. By
817864
default, uses '+gwhite+p1p' which draws a box around the legend
818865
using a 1 point black pen and adds a white background.
866+
{t}
819867
"""
820868
kwargs = self._preprocess(**kwargs)
821869

@@ -844,6 +892,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
844892
D="offset",
845893
G="fill",
846894
W="pen",
895+
t="transparency",
847896
)
848897
@kwargs_to_strings(
849898
R="sequence",
@@ -949,6 +998,7 @@ def text(
949998
Sets the pen used to draw a rectangle around the text string
950999
(see *clearance*) [Default is width = default, color = black,
9511000
style = solid].
1001+
{t}
9521002
"""
9531003
kwargs = self._preprocess(**kwargs)
9541004

@@ -998,7 +1048,13 @@ def text(
9981048
lib.call_module("text", arg_str)
9991049

10001050
@fmt_docstring
1001-
@use_alias(R="region", J="projection", B="frame", C="offset")
1051+
@use_alias(
1052+
R="region",
1053+
J="projection",
1054+
B="frame",
1055+
C="offset",
1056+
t="transparency",
1057+
)
10021058
@kwargs_to_strings(R="sequence")
10031059
def meca(
10041060
self,
@@ -1094,6 +1150,7 @@ def meca(
10941150
{J}
10951151
{R}
10961152
{B}
1153+
{t}
10971154
"""
10981155

10991156
# pylint warnings that need to be fixed

pygmt/helpers/decorators.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
``[g|p]``
8383
Force output grid to be gridline (g) or pixel (p) node registered.
8484
Default is gridline (g).""",
85+
"t": """\
86+
transparency : float
87+
Set transparency level, in [0-100] percent range.
88+
Default is 0, i.e., opaque.
89+
Only visible when PDF or raster format output is selected.
90+
Only the PNG format selection adds a transparency layer
91+
in the image (for further processing). """,
8592
}
8693

8794

0 commit comments

Comments
 (0)