@@ -826,20 +826,24 @@ def text(
826
826
textfiles = None ,
827
827
x = None ,
828
828
y = None ,
829
+ position = None ,
829
830
text = None ,
830
831
angle = None ,
831
832
font = None ,
832
833
justify = None ,
833
834
** kwargs ,
834
835
):
835
836
"""
836
- Plot or typeset text on maps
837
+ Plot or typeset text strings of variable size, font type, and
838
+ orientation.
837
839
838
840
Used to be pstext.
839
841
840
- Takes in textfile(s) or (x,y,text) triples as input.
842
+ Must provide at least one of the following combinations as input:
841
843
842
- Must provide at least *textfiles* or *x*, *y*, and *text*.
844
+ - *textfiles*
845
+ - *x*, *y*, and *text*
846
+ - *position* and *text*
843
847
844
848
Full option list at :gmt-docs:`text.html`
845
849
@@ -853,6 +857,17 @@ def text(
853
857
x/y : float or 1d arrays
854
858
The x and y coordinates, or an array of x and y coordinates to plot
855
859
the text
860
+ position : str
861
+ Sets reference point on the map for the text by using x,y
862
+ coordinates extracted from *region* instead of providing them
863
+ through *x* and *y*. Specify with a two letter (order independent)
864
+ code, chosen from:
865
+
866
+ * Horizontal: L(eft), C(entre), R(ight)
867
+ * Vertical: T(op), M(iddle), B(ottom)
868
+
869
+ For example, position="TL" plots the text at the Upper Left corner
870
+ of the map.
856
871
text : str or 1d array
857
872
The text string, or an array of strings to plot on the figure
858
873
angle: int, float, str or bool
@@ -899,17 +914,34 @@ def text(
899
914
"""
900
915
kwargs = self ._preprocess (** kwargs )
901
916
902
- kind = data_kind (textfiles , x , y , text )
917
+ # Ensure inputs are either textfiles, x/y/text, or position/text
918
+ if position is None :
919
+ kind = data_kind (textfiles , x , y , text )
920
+ elif position is not None :
921
+ if x is not None or y is not None :
922
+ raise GMTInvalidInput (
923
+ "Provide either position only, or x/y pairs, not both"
924
+ )
925
+ kind = "vectors"
926
+
903
927
if kind == "vectors" and text is None :
904
- raise GMTInvalidInput ("Must provide text with x and y. " )
928
+ raise GMTInvalidInput ("Must provide text with x/y pairs or position " )
905
929
if kind == "file" :
906
930
for textfile in textfiles .split (" " ): # ensure that textfile(s) exist
907
931
if not os .path .exists (textfile ):
908
932
raise GMTInvalidInput (f"Cannot find the file: { textfile } " )
909
933
910
- if angle is not None or font is not None or justify is not None :
934
+ # Build the `-F` argument in gmt text.
935
+ if (
936
+ position is not None
937
+ or angle is not None
938
+ or font is not None
939
+ or justify is not None
940
+ ):
911
941
if "F" not in kwargs .keys ():
912
942
kwargs .update ({"F" : "" })
943
+ if position is not None and isinstance (position , str ):
944
+ kwargs ["F" ] += f"+c{ position } "
913
945
if angle is not None and isinstance (angle , (int , float , str )):
914
946
kwargs ["F" ] += f"+a{ str (angle )} "
915
947
if font is not None and isinstance (font , str ):
0 commit comments