|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import dataclasses |
| 6 | +from typing import Any, Literal |
| 7 | + |
6 | 8 | from pygmt.alias import Alias |
7 | 9 | from pygmt.params.base import BaseParam |
8 | | -from typing import Any |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @dataclasses.dataclass(repr=False) |
@@ -53,25 +54,77 @@ class Axis(BaseParam): |
53 | 54 | """ |
54 | 55 | Class for setting up one axis of a plot. |
55 | 56 |
|
| 57 | + Attributes |
| 58 | + ---------- |
| 59 | + interval |
| 60 | + Intervals for annotations and major tick spacing, minor tick spacing, and/or |
| 61 | + grid line spacing. |
| 62 | + angle |
| 63 | + Plot slanted annotations (for Cartesian plots only), where *angle* is measured |
| 64 | + with respect to the horizontal and must be in the -90 <= *angle* <= 90 range. |
| 65 | + Default is normal (i.e., ``angle=90``) for y-axis and parallel (i.e., |
| 66 | + ``angle=0``) for x-axis annotations. These defaults can be changed via |
| 67 | + :gmt-term:`MAP_ANNOT_ORTHO`. |
| 68 | + skip_edge |
| 69 | + Skip annotations that fall exactly at the ends of the axis. Choose from ``left`` |
| 70 | + or ``right`` to skip only the lower or upper annotation, respectively, or |
| 71 | + ``True`` to skip both. |
| 72 | + fancy |
| 73 | + Give fancy annotations with W|E|S|N suffixes encoding the sign (for geographic |
| 74 | + axes only). |
| 75 | + label/hlabel |
| 76 | + Add a label to the axis (for Cartesian plots only). The label is placed parallel |
| 77 | + to the axis by default; use **hlabel** to force a horizontal label for y-axis, |
| 78 | + which is useful for very short labels. |
| 79 | + alt_label/alt_hlabel |
| 80 | + Add an alternate label for the right or upper axes. The label is placed parallel |
| 81 | + to the axis by default; use **alt_hlabel** to force a horizontal label for |
| 82 | + y-axis, which is useful for very short labels. [For Cartesian plots only]. |
| 83 | + prefix |
| 84 | + Add a leading text prefix for axis annotation (e.g., dollar sign for plots |
| 85 | + related to money) (for Cartesian plots only). For geographic maps the addition |
| 86 | + of degree symbols, etc. is automatic and controlled by |
| 87 | + :gmt-term:`FORMAT_GEO_MAP`. |
| 88 | + unit |
| 89 | + Append a unit to the annotations (for Cartesian plots only). For geographic maps |
| 90 | + the addition of degree symbols, etc. is automatic and controlled by |
| 91 | + :gmt-term:`FORMAT_GEO_MAP`. |
| 92 | +
|
56 | 93 | Examples |
57 | 94 | -------- |
58 | 95 | >>> from pygmt.params import Axis |
59 | 96 | >>> str(Axis(10, angle=30, label="X axis", unit="km")) |
60 | 97 | '10+a30+lX axis+ukm' |
61 | 98 | """ |
62 | 99 |
|
63 | | - interval: float | str |
64 | | - angle: float | str | None = None |
| 100 | + interval: float | str # How to make it more Pythonic? |
| 101 | + angle: float | None = None |
| 102 | + skip_edge: Literal["left", "right"] | bool = False |
| 103 | + fancy: bool = False |
65 | 104 | label: str | None = None |
| 105 | + hlabel: str | None = None |
| 106 | + alt_label: str | None = None |
| 107 | + alt_hlabel: str | None = None |
| 108 | + prefix: str | None = None |
66 | 109 | unit: str | None = None |
67 | 110 |
|
68 | 111 | @property |
69 | 112 | def _aliases(self): |
70 | 113 | return [ |
71 | | - Alias(self.interval), |
72 | | - Alias(self.angle, prefix="+a"), |
73 | | - Alias(self.label, prefix="+l"), |
74 | | - Alias(self.unit, prefix="+u"), |
| 114 | + Alias(self.interval, name="interval"), |
| 115 | + Alias(self.angle, name="angle", prefix="+a"), |
| 116 | + Alias( |
| 117 | + self.skip_edge, |
| 118 | + name="skip_edge", |
| 119 | + prefix="+e", |
| 120 | + mapping={True: True, "left": "l", "right": "r"}, |
| 121 | + ), |
| 122 | + Alias(self.fancy, name="fancy", prefix="+f"), |
| 123 | + Alias(self.label, name="label", prefix="+l"), |
| 124 | + Alias(self.hlabel, name="hlabel", prefix="+L"), |
| 125 | + Alias(self.alt_label, name="alt_label", prefix="+s"), |
| 126 | + Alias(self.alt_hlabel, name="alt_hlabel", prefix="+S"), |
| 127 | + Alias(self.unit, name="unit", prefix="+u"), |
75 | 128 | ] |
76 | 129 |
|
77 | 130 |
|
|
0 commit comments