Skip to content

Commit 56ba083

Browse files
authored
Add common alias perspective (p) for plotting 3D illustrations (#627)
Used to select a perspective view by setting the azimuth and elevation angle of the viewpoint. See https://docs.generic-mapping-tools.org/6.1/gmt.html#perspective-full and https://docs.generic-mapping-tools.org/6.1/cookbook/options.html#perspective-view-the-p-option
1 parent faf197e commit 56ba083

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

pygmt/base_plotting.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use
7070
U="timestamp",
7171
X="xshift",
7272
Y="yshift",
73+
p="perspective",
7374
t="transparency",
7475
)
75-
@kwargs_to_strings(R="sequence")
76+
@kwargs_to_strings(R="sequence", p="sequence")
7677
def coast(self, **kwargs):
7778
"""
7879
Plot continents, shorelines, rivers, and borders on maps
@@ -132,6 +133,7 @@ def coast(self, **kwargs):
132133
``'[level/]pen'``
133134
Draw shorelines [Default is no shorelines]. Append pen attributes.
134135
{XY}
136+
{p}
135137
{t}
136138
137139
"""
@@ -151,9 +153,10 @@ def coast(self, **kwargs):
151153
W="scale",
152154
X="xshift",
153155
Y="yshift",
156+
p="perspective",
154157
t="transparency",
155158
)
156-
@kwargs_to_strings(R="sequence", G="sequence")
159+
@kwargs_to_strings(R="sequence", G="sequence", p="sequence")
157160
def colorbar(self, **kwargs):
158161
"""
159162
Plot a gray or color scale-bar on maps.
@@ -214,6 +217,7 @@ def colorbar(self, **kwargs):
214217
Multiply all z-values in the CPT by the provided scale. By default
215218
the CPT is used as is.
216219
{XY}
220+
{p}
217221
{t}
218222
219223
"""
@@ -237,9 +241,10 @@ def colorbar(self, **kwargs):
237241
l="label",
238242
X="xshift",
239243
Y="yshift",
244+
p="perspective",
240245
t="transparency",
241246
)
242-
@kwargs_to_strings(R="sequence", L="sequence", A="sequence_plus")
247+
@kwargs_to_strings(R="sequence", L="sequence", A="sequence_plus", p="sequence")
243248
def grdcontour(self, grid, **kwargs):
244249
"""
245250
Convert grids or images to contours and plot them on maps
@@ -295,6 +300,7 @@ def grdcontour(self, grid, **kwargs):
295300
to be of the format [*annotcontlabel*][/*contlabel*]. If either
296301
label contains a slash (/) character then use ``|`` as the
297302
separator for the two labels instead.
303+
{p}
298304
{t}
299305
"""
300306
kwargs = self._preprocess(**kwargs)
@@ -320,10 +326,11 @@ def grdcontour(self, grid, **kwargs):
320326
C="cmap",
321327
X="xshift",
322328
Y="yshift",
329+
p="perspective",
323330
t="transparency",
324331
x="cores",
325332
)
326-
@kwargs_to_strings(R="sequence")
333+
@kwargs_to_strings(R="sequence", p="sequence")
327334
def grdimage(self, grid, **kwargs):
328335
"""
329336
Project grids or images and plot them on maps.
@@ -339,6 +346,7 @@ def grdimage(self, grid, **kwargs):
339346
grid : str or xarray.DataArray
340347
The file name of the input grid or the grid loaded as a DataArray.
341348
{XY}
349+
{p}
342350
{t}
343351
{x}
344352
@@ -370,10 +378,10 @@ def grdimage(self, grid, **kwargs):
370378
Wc="contourpen",
371379
Wm="meshpen",
372380
Wf="facadepen",
373-
p="perspective",
374381
I="shading",
375382
X="xshift",
376383
Y="yshift",
384+
p="perspective",
377385
t="transparency",
378386
)
379387
@kwargs_to_strings(R="sequence", p="sequence")
@@ -438,10 +446,6 @@ def grdview(self, grid, **kwargs):
438446
Sets the pen attributes used for the facade. You must also select
439447
-N for the facade outline to be drawn.
440448
441-
perspective : list or str
442-
``'[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]'``.
443-
Select perspective view.
444-
445449
shading : str
446450
Provide the name of a grid file with intensities in the (-1,+1)
447451
range, or a constant intensity to apply everywhere (affects the
@@ -452,6 +456,7 @@ def grdview(self, grid, **kwargs):
452456
``+d`` to select the default arguments (``+a-45+nt1+m0``).
453457
454458
{XY}
459+
{p}
455460
{t}
456461
457462
"""
@@ -495,9 +500,10 @@ def grdview(self, grid, **kwargs):
495500
U="timestamp",
496501
X="xshift",
497502
Y="yshift",
503+
p="perspective",
498504
t="transparency",
499505
)
500-
@kwargs_to_strings(R="sequence", i="sequence_comma")
506+
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
501507
def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
502508
"""
503509
Plot lines, polygons, and symbols on maps.
@@ -567,6 +573,7 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
567573
label : str
568574
Add a legend entry for the symbol or line being plotted.
569575
576+
{p}
570577
{t}
571578
"""
572579
kwargs = self._preprocess(**kwargs)
@@ -619,9 +626,10 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
619626
C="levels",
620627
X="xshift",
621628
Y="yshift",
629+
p="perspective",
622630
t="transparency",
623631
)
624-
@kwargs_to_strings(R="sequence", i="sequence_comma")
632+
@kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence")
625633
def contour(self, x=None, y=None, z=None, data=None, **kwargs):
626634
"""
627635
Contour table data by direct triangulation.
@@ -678,6 +686,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
678686
label contains a slash (/) character then use ``|`` as the
679687
separator for the two labels instead.
680688
{XY}
689+
{p}
681690
{t}
682691
683692
"""
@@ -711,9 +720,10 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
711720
U="timestamp",
712721
X="xshift",
713722
Y="yshift",
723+
p="perspective",
714724
t="transparency",
715725
)
716-
@kwargs_to_strings(R="sequence")
726+
@kwargs_to_strings(R="sequence", p="sequence")
717727
def basemap(self, **kwargs):
718728
"""
719729
Produce a basemap for the figure.
@@ -746,6 +756,7 @@ def basemap(self, **kwargs):
746756
reference and anchor points
747757
{U}
748758
{XY}
759+
{p}
749760
{t}
750761
751762
"""
@@ -764,9 +775,10 @@ def basemap(self, **kwargs):
764775
F="box",
765776
X="xshift",
766777
Y="yshift",
778+
p="perspective",
767779
t="transparency",
768780
)
769-
@kwargs_to_strings(R="sequence")
781+
@kwargs_to_strings(R="sequence", p="sequence")
770782
def logo(self, **kwargs):
771783
"""
772784
Place the GMT graphics logo on a map.
@@ -792,6 +804,7 @@ def logo(self, **kwargs):
792804
GMT logo.
793805
{U}
794806
{XY}
807+
{p}
795808
{t}
796809
797810
"""
@@ -810,9 +823,10 @@ def logo(self, **kwargs):
810823
M="monochrome",
811824
X="xshift",
812825
Y="yshift",
826+
p="perspective",
813827
t="transparency",
814828
)
815-
@kwargs_to_strings(R="sequence")
829+
@kwargs_to_strings(R="sequence", p="sequence")
816830
def image(self, imagefile, **kwargs):
817831
"""
818832
Place images or EPS files on maps.
@@ -846,6 +860,7 @@ def image(self, imagefile, **kwargs):
846860
Convert color image to monochrome grayshades using the (television)
847861
YIQ-transformation.
848862
{XY}
863+
{p}
849864
{t}
850865
"""
851866
kwargs = self._preprocess(**kwargs)
@@ -861,9 +876,10 @@ def image(self, imagefile, **kwargs):
861876
F="box",
862877
X="xshift",
863878
Y="yshift",
879+
p="perspective",
864880
t="transparency",
865881
)
866-
@kwargs_to_strings(R="sequence")
882+
@kwargs_to_strings(R="sequence", p="sequence")
867883
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
868884
"""
869885
Plot legends on maps.
@@ -898,6 +914,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
898914
default, uses '+gwhite+p1p' which draws a box around the legend
899915
using a 1 point black pen and adds a white background.
900916
{XY}
917+
{p}
901918
{t}
902919
"""
903920
kwargs = self._preprocess(**kwargs)
@@ -929,6 +946,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
929946
W="pen",
930947
X="xshift",
931948
Y="yshift",
949+
p="perspective",
932950
t="transparency",
933951
)
934952
@kwargs_to_strings(
@@ -937,6 +955,7 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
937955
angle="sequence_comma",
938956
font="sequence_comma",
939957
justify="sequence_comma",
958+
p="sequence",
940959
)
941960
def text(
942961
self,
@@ -1036,6 +1055,7 @@ def text(
10361055
(see *clearance*) [Default is width = default, color = black,
10371056
style = solid].
10381057
{XY}
1058+
{p}
10391059
{t}
10401060
"""
10411061
kwargs = self._preprocess(**kwargs)
@@ -1093,9 +1113,10 @@ def text(
10931113
C="offset",
10941114
X="xshift",
10951115
Y="yshift",
1116+
p="perspective",
10961117
t="transparency",
10971118
)
1098-
@kwargs_to_strings(R="sequence")
1119+
@kwargs_to_strings(R="sequence", p="sequence")
10991120
def meca(
11001121
self,
11011122
spec,
@@ -1191,6 +1212,7 @@ def meca(
11911212
{R}
11921213
{B}
11931214
{XY}
1215+
{p}
11941216
{t}
11951217
"""
11961218

pygmt/helpers/decorators.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
- 'c' for bicubic [Default]
8787
- 'l' for bilinear
8888
- 'n' for nearest-neighbor""",
89+
"p": """\
90+
perspective : list or str
91+
``'[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]'``.
92+
Select perspective view and set the azimuth and elevation angle of
93+
the viewpoint. Default is [180, 90]. Full documentation is at
94+
:gmt-docs:`gmt.html#perspective-full`.
95+
""",
8996
"registration": """\
9097
registration : str
9198
``[g|p]``

0 commit comments

Comments
 (0)