|
| 1 | +""" |
| 2 | +The frame parameter. |
| 3 | +""" |
| 4 | + |
| 5 | +from dataclasses import dataclass |
| 6 | +from typing import Any |
| 7 | + |
| 8 | +from pygmt.alias import Alias |
| 9 | +from pygmt.params.base import BaseParam |
| 10 | + |
| 11 | + |
| 12 | +@dataclass(repr=False) |
| 13 | +class Axes(BaseParam): |
| 14 | + """ |
| 15 | + Class for setting up the axes, title, and fill of a plot. |
| 16 | +
|
| 17 | + Examples |
| 18 | + -------- |
| 19 | + >>> from pygmt.params import Axes |
| 20 | + >>> str(Axes("WSen", title="My Plot Title", fill="lightred")) |
| 21 | + 'WSen+glightred+tMy Plot Title' |
| 22 | + """ |
| 23 | + |
| 24 | + axes: Any = None |
| 25 | + fill: Any = None |
| 26 | + title: Any = None |
| 27 | + |
| 28 | + @property |
| 29 | + def _aliases(self): |
| 30 | + return [ |
| 31 | + Alias(self.axes), |
| 32 | + Alias(self.fill, prefix="+g"), |
| 33 | + Alias(self.title, prefix="+t"), |
| 34 | + ] |
| 35 | + |
| 36 | + |
| 37 | +@dataclass(repr=False) |
| 38 | +class Axis(BaseParam): |
| 39 | + """ |
| 40 | + Class for setting up one axis of a plot. |
| 41 | +
|
| 42 | + Examples |
| 43 | + -------- |
| 44 | + >>> from pygmt.params import Axis |
| 45 | + >>> str(Axis(10, angle=30, label="X axis", unit="km")) |
| 46 | + '10+a30+lX axis+ukm' |
| 47 | + """ |
| 48 | + |
| 49 | + interval: float | str |
| 50 | + angle: float | str | None = None |
| 51 | + label: str | None = None |
| 52 | + unit: str | None = None |
| 53 | + |
| 54 | + @property |
| 55 | + def _aliases(self): |
| 56 | + return [ |
| 57 | + Alias(self.interval), |
| 58 | + Alias(self.angle, prefix="+a"), |
| 59 | + Alias(self.label, prefix="+l"), |
| 60 | + Alias(self.unit, prefix="+u"), |
| 61 | + ] |
| 62 | + |
| 63 | + |
| 64 | +@dataclass(repr=False) |
| 65 | +class Frame(BaseParam): |
| 66 | + """ |
| 67 | + Class for setting up the frame of a plot. |
| 68 | +
|
| 69 | + >>> from pygmt.alias import AliasSystem, Alias |
| 70 | + >>> from pygmt.params import Frame, Axes, Axis |
| 71 | + >>> frame = Frame( |
| 72 | + ... axes=Axes("WSen", title="My Plot Title", fill="lightred"), |
| 73 | + ... xaxis=Axis(10, angle=30, label="X axis", unit="km"), |
| 74 | + ... ) |
| 75 | + >>> def func(frame): |
| 76 | + ... alias = AliasSystem(B=Alias(frame)) |
| 77 | + ... return alias.kwdict |
| 78 | + >>> dict(func(frame)) |
| 79 | + {'B': ['WSen+glightred+tMy Plot Title', 'x10+a30+lX axis+ukm']} |
| 80 | + """ |
| 81 | + |
| 82 | + axes: Any = None |
| 83 | + xaxis: Any = None |
| 84 | + yaxis: Any = None |
| 85 | + zaxis: Any = None |
| 86 | + |
| 87 | + @property |
| 88 | + def _aliases(self): |
| 89 | + return [ |
| 90 | + Alias(self.axes), |
| 91 | + Alias(self.xaxis, prefix="x"), |
| 92 | + Alias(self.yaxis, prefix="y"), |
| 93 | + Alias(self.zaxis, prefix="z"), |
| 94 | + ] |
| 95 | + |
| 96 | + def __iter__(self): |
| 97 | + """ |
| 98 | + Iterate over the aliases of the class. |
| 99 | +
|
| 100 | + Yields |
| 101 | + ------ |
| 102 | + The value of each alias in the class. None are excluded. |
| 103 | + """ |
| 104 | + yield from (alias._value for alias in self._aliases if alias._value is not None) |
0 commit comments