66from collections .abc import Sequence
77from typing import Literal
88
9+ from pygmt ._typing import AnchorCode
910from pygmt .alias import Alias , AliasSystem
1011from pygmt .clib import Session
1112from pygmt .exceptions import GMTInvalidInput , GMTValueError
12- from pygmt .helpers import (
13- build_arg_list ,
14- fmt_docstring ,
15- kwargs_to_strings ,
16- use_alias ,
17- )
13+ from pygmt .helpers import build_arg_list , fmt_docstring , kwargs_to_strings , use_alias
14+ from pygmt .params import Box
1815
1916
2017@fmt_docstring
2926 T = "title" ,
3027)
3128@kwargs_to_strings (Ff = "sequence" , Fs = "sequence" )
32- def subplot (
29+ def subplot ( # noqa: PLR0913
3330 self ,
3431 nrows = 1 ,
3532 ncols = 1 ,
33+ autotag : str | bool = False ,
34+ tag_box : Box | None = None ,
35+ tag_offset : float | str | Sequence [float | str ] | None = None ,
36+ tag_position : AnchorCode | None = None ,
37+ tag_orientation : Literal ["horizontal" , "vertical" ] | None = None ,
38+ tag_number_style : Literal ["arabic" , "roman" , "Roman" ] | None = None ,
39+ tag_font : str | None = None ,
3640 margins : float | str | Sequence [float | str ] | None = None ,
3741 projection : str | None = None ,
3842 frame : str | Sequence [str ] | bool = False ,
@@ -71,31 +75,48 @@ def subplot(
7175 Specify the dimensions of each subplot directly as [*width*, *height*].
7276 Note that only one of ``figsize`` or ``subsize`` can be provided at
7377 once.
78+ autotag
79+ Specify automatic tagging of each subplot. It can accept a number, or a letter.
80+ The number or letter can be surrounded by parentheses on any side if these
81+ should be typeset as part of the tag. This sets the tag of the first, top-left
82+ subplot and others follow sequentially. If set to ``True``, default to ``"a)"``.
83+
84+ Examples are:
85+
86+ - ``autotag="a"``: tags are ``a``, ``b``, ``c``, ...
87+ - ``autotag="1"``: tags are ``1``, ``2``, ``3``, ...
88+ - ``autotag="a)"``: tags are ``a)``, ``b)``, ``c)``, ...
89+ - ``autotag="(c)"``: tags are ``(c)``, ``(d)``, ``(e)``, ...
90+ - ``autotag=True``: same as ``autotag="a)"``.
91+ tag_box
92+ Draw a box around the subplot tag. See :class:`pygmt.params.Box` for details on
93+ how to specify the box.
94+
95+ **Notes on the use of the ``Box`` class:**
7496
75- autolabel : bool or str
76- [*autolabel*][**+c**\ *dx*\ [/*dy*]][**+g**\ *fill*][**+j**\|\ **J**\
77- *refpoint*][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+r**\|\ **R**]\ [**+v**].
78- Specify automatic tagging of each subplot. Append either a number or letter
79- [Default is ``"a"``]. This sets the tag of the first, top-left subplot and
80- others follow sequentially. Surround the number or letter by parentheses on
81- any side if these should be typeset as part of the tag [Default is ``")"``].
82- Use **+j**\|\ **J** for setting *refpoint* via a
83- :doc:`2-character justification code </techref/justification_codes>`
84- to specify where the tag should be placed in the subplot [Default is ``"TL"``
85- for the Top Left corner]. **Note**: **+j** sets the justification of the tag
86- to *refpoint* (suitable for interior tags) while **+J** instead selects the
87- mirror opposite (suitable for exterior tags). Append **+c**\ *dx*\[/*dy*] to
88- set the clearance between the tag and a surrounding text box requested via
89- **+g** or **+p** [Default is ``"3p/3p"``, i.e., 15 % of the
90- :gmt-term:`FONT_TAG` size dimension]. Append **+g**\ *fill* to paint the tag's
91- text box with *fill* [Default is no fill]. Append **+o**\ *dx*\ [/*dy*] to
92- offset the tag's reference point in the direction implied by the justification
93- [Default is ``"4p/4p"``, i.e., 20 % of the :gmt-term:`FONT_TAG` size]. Append
94- **+p**\ *pen* to draw the outline of the tag's text box using the selected *pen*
95- [Default is no outline]. Append **+r** to typeset your tag numbers using
96- lowercase Roman numerals; use **+R** for uppercase Roman numerals [Default is
97- Arabic numerals]. Append **+v** to increase tag numbers vertically down columns
98- [Default is horizontally across rows].
97+ - The property ``clearance`` cannot be four values.
98+ - The property ``inner_pen``/``inner_gap``/``radius`` is not supported.
99+ tag_position
100+ Position of the subplot tag. It can be specified using a
101+ :doc:`2-character justification code </techref/justification_codes>`. If not
102+ specified, defaults to ``"TL"`` (Top Left corner).
103+ tag_offset
104+ Offset of the subplot tag in the direction implied by the justification. It can
105+ be a single value or a sequence of two values specifying the x- and y-offsets.
106+ [Default to ``"4p/4p"``, i.e., 20 % of the :gmt-term:`FONT_TAG` size].
107+ tag_orientation
108+ Orientation of the subplot tag. It can be:
109+
110+ - ``"horizontal"``: Increase tag numbers horizontally across rows [Default].
111+ - ``"vertical"``: Increase tag numbers vertically down columns.
112+ tag_number_style
113+ Style of the subplot tag numbers. It can be:
114+
115+ - ``"arabic"``: Arabic numerals: 1, 2, 3, ... [Default].
116+ - ``"roman"``: Lowercase Roman numerals: i, ii, iii, ...
117+ - ``"Roman"``: Uppercase Roman numerals: I, II, III, ...
118+ tag_font
119+ Font for the subplot tag. [Default to ``"20p,Helvetica,black"``].
99120 $frame
100121 clearance : str or list
101122 [*side*]\ *clearance*.
@@ -174,6 +195,22 @@ def subplot(
174195 raise GMTInvalidInput (msg )
175196
176197 aliasdict = AliasSystem (
198+ A = [
199+ Alias (autotag , name = "autotag" ),
200+ Alias (tag_box , name = "tag_box" ),
201+ Alias (tag_offset , name = "tag_offset" , prefix = "+o" , sep = "/" , size = 2 ),
202+ Alias (tag_position , name = "tag_position" , prefix = "+j" ),
203+ Alias (
204+ tag_orientation ,
205+ name = "tag_orientation" ,
206+ mapping = {"horizontal" : "" , "vertical" : "+v" },
207+ ),
208+ Alias (
209+ tag_number_style ,
210+ name = "tag_number_style" ,
211+ mapping = {"arabic" : "" , "roman" : "+r" , "Roman" : "+R" },
212+ ),
213+ ],
177214 M = Alias (margins , name = "margins" , sep = "/" , size = (2 , 4 )),
178215 ).add_common (
179216 B = frame ,
@@ -183,6 +220,9 @@ def subplot(
183220 )
184221 aliasdict .merge (kwargs )
185222
223+ # Configure FONT_TAG if tag_font is set
224+ confdict = {"FONT_TAG" : tag_font } if tag_font is not None else {}
225+
186226 # Need to use separate sessions for "subplot begin" and "subplot end".
187227 # Otherwise, "subplot end" will use the last session, which may cause
188228 # strange positioning issues for later plotting calls.
@@ -191,7 +231,11 @@ def subplot(
191231 with Session () as lib :
192232 lib .call_module (
193233 module = "subplot" ,
194- args = ["begin" , f"{ nrows } x{ ncols } " , * build_arg_list (aliasdict )],
234+ args = [
235+ "begin" ,
236+ f"{ nrows } x{ ncols } " ,
237+ * build_arg_list (aliasdict , confdict = confdict ),
238+ ],
195239 )
196240 yield
197241 finally :
0 commit comments