Skip to content

WIP: Add the Axes, Axis, Frame classes for the frame parameter #4016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: AliasSystem/params/base
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions pygmt/params/frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""
The frame parameter.
"""

from dataclasses import dataclass
from typing import Any

from pygmt.alias import Alias
from pygmt.params.base import BaseParam


@dataclass(repr=False)
class Axes(BaseParam):
"""
Class for setting up the axes, title, and fill of a plot.

Examples
--------
>>> from pygmt.params import Axes
>>> str(Axes("WSen", title="My Plot Title", fill="lightred"))
'WSen+glightred+tMy Plot Title'
"""

axes: Any = None
fill: Any = None
title: Any = None

@property
def _aliases(self):
return [
Alias(self.axes),
Alias(self.fill, prefix="+g"),
Alias(self.title, prefix="+t"),
]


@dataclass(repr=False)
class Axis(BaseParam):
"""
Class for setting up one axis of a plot.

Examples
--------
>>> from pygmt.params import Axis
>>> str(Axis(10, angle=30, label="X axis", unit="km"))
'10+a30+lX axis+ukm'
"""

interval: float | str
angle: float | str | None = None
label: str | None = None
unit: str | None = None

@property
def _aliases(self):
return [
Alias(self.interval),
Alias(self.angle, prefix="+a"),
Alias(self.label, prefix="+l"),
Alias(self.unit, prefix="+u"),
]


@dataclass(repr=False)
class Frame(BaseParam):
"""
Class for setting up the frame of a plot.

>>> from pygmt.alias import AliasSystem, Alias
>>> from pygmt.params import Frame, Axes, Axis
>>> frame = Frame(
... axes=Axes("WSen", title="My Plot Title", fill="lightred"),
... xaxis=Axis(10, angle=30, label="X axis", unit="km"),
... )
>>> def func(frame):
... alias = AliasSystem(B=Alias(frame))
... return alias.kwdict
>>> dict(func(frame))
{'B': ['WSen+glightred+tMy Plot Title', 'x10+a30+lX axis+ukm']}
"""

axes: Any = None
xaxis: Any = None
yaxis: Any = None
zaxis: Any = None

@property
def _aliases(self):
return [
Alias(self.axes),
Alias(self.xaxis, prefix="x"),
Alias(self.yaxis, prefix="y"),
Alias(self.zaxis, prefix="z"),
]

def __iter__(self):
"""
Iterate over the aliases of the class.

Yields
------
The value of each alias in the class. None are excluded.
"""
yield from (alias._value for alias in self._aliases if alias._value is not None)
Loading