|
11 | 11 | from pygmt.exceptions import GMTValueError |
12 | 12 | from pygmt.helpers import build_arg_list, fmt_docstring, use_alias |
13 | 13 | from pygmt.helpers.utils import is_nonstr_iter |
14 | | -from pygmt.params import Box, Position |
| 14 | +from pygmt.params import Axis, Box, Frame, Position |
15 | 15 | from pygmt.src._common import _parse_position |
16 | 16 |
|
17 | 17 | __doctest_skip__ = ["colorbar"] |
18 | 18 |
|
19 | 19 |
|
| 20 | +def _build_frame( |
| 21 | + annot: float | None = None, |
| 22 | + tick: float | None = None, |
| 23 | + grid: float | None = None, |
| 24 | + annot_angel: float | None = None, |
| 25 | + annot_prefix: str | None = None, |
| 26 | + annot_unit: str | None = None, |
| 27 | + xlabel: str | None = None, |
| 28 | + ylabel: str | None = None, |
| 29 | + frame = None, |
| 30 | +): |
| 31 | + """ |
| 32 | + Create the list of Alias objects for the -B option. |
| 33 | +
|
| 34 | + >>> _build_frame(annot=1, tick=0.5, xlabel="Distance", ylabel="Depth") |
| 35 | + Frame(xaxis=Axis(annot=1, tick=0.5, label='Distance'), yaxis=Axis(label='Depth')) |
| 36 | + """ |
| 37 | + if frame is not None and frame is not False: |
| 38 | + return frame |
| 39 | + |
| 40 | + _xaxis_is_set = any( |
| 41 | + v is not None |
| 42 | + for v in {annot, tick, grid, annot_angel, annot_prefix, annot_unit, xlabel} |
| 43 | + ) |
| 44 | + _yaxis_is_set = ylabel is not None |
| 45 | + |
| 46 | + # Need to return None if no parameters are give. Otherwise, it may return "". |
| 47 | + if not (_xaxis_is_set or _yaxis_is_set): |
| 48 | + return None |
| 49 | + |
| 50 | + xaxis, yaxis = None, None |
| 51 | + if _xaxis_is_set: |
| 52 | + xaxis = Axis( |
| 53 | + annot=annot, |
| 54 | + tick=tick, |
| 55 | + grid=grid, |
| 56 | + # angle=annot_angel, |
| 57 | + # prefix=annot_prefix, |
| 58 | + # unit=annot_unit, |
| 59 | + label=xlabel, |
| 60 | + ) |
| 61 | + if _yaxis_is_set: |
| 62 | + yaxis = Axis(label=ylabel) |
| 63 | + return Frame(xaxis=xaxis, yaxis=yaxis) |
| 64 | + |
| 65 | + |
20 | 66 | def _alias_option_D( # noqa: N802, PLR0913 |
21 | 67 | position=None, |
22 | 68 | length=None, |
@@ -153,6 +199,14 @@ def colorbar( # noqa: PLR0913 |
153 | 199 | length: float | str | None = None, |
154 | 200 | width: float | str | None = None, |
155 | 201 | orientation: Literal["horizontal", "vertical"] | None = None, |
| 202 | + annot: float | None = None, |
| 203 | + tick: float | None = None, |
| 204 | + grid: float | None = None, |
| 205 | + annot_angel: float | None = None, |
| 206 | + annot_prefix: str | None = None, |
| 207 | + annot_unit: str | None = None, |
| 208 | + xlabel: str | None = None, |
| 209 | + ylabel: str | None = None, |
156 | 210 | reverse: bool = False, |
157 | 211 | nan: bool = False, |
158 | 212 | nan_position: Literal["start", "end"] | None = None, |
@@ -337,10 +391,9 @@ def colorbar( # noqa: PLR0913 |
337 | 391 | >>> fig.basemap(region=[0, 10, 0, 3], projection="X10c/3c", frame=True) |
338 | 392 | >>> # Call the colorbar method for the plot |
339 | 393 | >>> fig.colorbar( |
340 | | - ... # Set cmap to the "roma" CPT |
341 | 394 | ... cmap="SCM/roma", |
342 | | - ... # Label the x-axis "Velocity" and the y-axis "m/s" |
343 | | - ... frame=["x+lVelocity", "y+lm/s"], |
| 395 | + ... xlabel="Velocity", |
| 396 | + ... ylabel="m/s", |
344 | 397 | ... ) |
345 | 398 | >>> # Show the plot |
346 | 399 | >>> fig.show() |
@@ -386,7 +439,17 @@ def colorbar( # noqa: PLR0913 |
386 | 439 | Q=Alias(log, name="log"), |
387 | 440 | W=Alias(scale, name="scale"), |
388 | 441 | ).add_common( |
389 | | - B=frame, |
| 442 | + B=_build_frame( |
| 443 | + annot=annot, |
| 444 | + tick=tick, |
| 445 | + grid=grid, |
| 446 | + annot_angel=annot_angel, |
| 447 | + annot_prefix=annot_prefix, |
| 448 | + annot_unit=annot_unit, |
| 449 | + xlabel=xlabel, |
| 450 | + ylabel=ylabel, |
| 451 | + frame=frame, |
| 452 | + ), |
390 | 453 | J=projection, |
391 | 454 | R=region, |
392 | 455 | V=verbose, |
|
0 commit comments