|
3 | 3 | """
|
4 | 4 |
|
5 | 5 | from pygmt.clib import Session
|
6 |
| -from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias |
| 6 | +from pygmt.helpers import ( |
| 7 | + build_arg_list, |
| 8 | + fmt_docstring, |
| 9 | + is_nonstr_iter, |
| 10 | + kwargs_to_strings, |
| 11 | + use_alias, |
| 12 | +) |
7 | 13 |
|
8 | 14 |
|
9 | 15 | @fmt_docstring
|
@@ -54,23 +60,26 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs):
|
54 | 60 | Arrays of x and y coordinates and values z of the data points.
|
55 | 61 | {projection}
|
56 | 62 | {region}
|
57 |
| - annotation : str or int |
| 63 | + annotation : float, list, or str |
58 | 64 | Specify or disable annotated contour levels, modifies annotated
|
59 | 65 | contours specified in ``levels``.
|
60 | 66 |
|
61 |
| - - Specify a fixed annotation interval *annot_int* or a |
62 |
| - single annotation level +\ *annot_int*. |
| 67 | + - Specify a fixed annotation interval. |
| 68 | + - Specify a list of annotation levels. |
| 69 | + - Disable all annotations by setting ``annotation="n"``. |
| 70 | + - Adjust the appearance by appending different modifiers, e.g., |
| 71 | + ``"annot_int+f10p+gred"`` gives annotations with a font size of 10 points and |
| 72 | + a red filled box. For all available modifiers see :gmt-docs:`contour.html#a`. |
63 | 73 | {frame}
|
64 |
| - levels : str or int |
| 74 | + levels : float, list, or str |
65 | 75 | Specify the contour lines to generate.
|
66 | 76 |
|
67 |
| - - The file name of a CPT file where the color boundaries will |
68 |
| - be used as contour levels. |
69 |
| - - The file name of a 2 (or 3) column file containing the contour |
70 |
| - levels (col 1), (**C**)ontour or (**A**)nnotate (col 2), and optional |
71 |
| - angle (col 3). |
72 |
| - - A fixed contour interval *cont_int* or a single contour with |
73 |
| - +\ *cont_int*. |
| 77 | + - The file name of a CPT file where the color boundaries will be used as |
| 78 | + contour levels. |
| 79 | + - The file name of a 2 (or 3) column file containing the contour levels (col 0), |
| 80 | + (**C**)ontour or (**A**)nnotate (col 1), and optional angle (col 2). |
| 81 | + - A fixed contour interval. |
| 82 | + - A list of contour levels. |
74 | 83 | D : str
|
75 | 84 | Dump contour coordinates.
|
76 | 85 | E : str
|
@@ -114,6 +123,17 @@ def contour(self, data=None, x=None, y=None, z=None, **kwargs):
|
114 | 123 | """
|
115 | 124 | kwargs = self._preprocess(**kwargs)
|
116 | 125 |
|
| 126 | + # Specify levels for contours or annotations. |
| 127 | + # One level is converted to a string with a trailing comma to separate it from |
| 128 | + # specifying an interval. |
| 129 | + # Multiple levels are concatenated to a comma-separated string. |
| 130 | + for arg in ["A", "C"]: |
| 131 | + if is_nonstr_iter(kwargs.get(arg)): |
| 132 | + if len(kwargs[arg]) == 1: # One level |
| 133 | + kwargs[arg] = str(kwargs[arg][0]) + "," |
| 134 | + else: # Multiple levels |
| 135 | + kwargs[arg] = ",".join(f"{item}" for item in kwargs[arg]) |
| 136 | + |
117 | 137 | with Session() as lib:
|
118 | 138 | with lib.virtualfile_in(
|
119 | 139 | check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
|
|
0 commit comments