Add the Position class for GMT embellishment placement#4212
Conversation
pygmt/params/position.py
Outdated
|
|
||
| #: Specify the reference point on the plot. The method of defining the reference | ||
| #: point is controlled by ``type``, and the exact location is set by ``position``. | ||
| location: Sequence[float | str] | AnchorCode |
There was a problem hiding this comment.
I think location is better as the parameter is already called position and we overall will have the Position class.
There was a problem hiding this comment.
The docstring above calls this 'reference point', so how about something like ref or refpt?
There was a problem hiding this comment.
Maybe refpoint?
In fact, I'd prefer to make it a positional-only parameter, so it will be used like Position("TL", type="inside"), Position((1, 2)).
In this case, the specific parameter name doesn't really matter, though dataclasses doesn't support positional-only attributes.
There was a problem hiding this comment.
Yeah, I did think of positional-only, but a little tricky with dataclasses as you said. Ok to got with refpoint, but let's see what @yvonnefroehlich thinks.
There was a problem hiding this comment.
I am fine with refpoint. Unfortunately, I have only little experience with positional-only parameters.
|
Ping @GenericMappingTools/pygmt-maintainers for final reviews. I plan to merge it in 48 hours if no further comments. |
| .. figure:: https://docs.generic-mapping-tools.org/dev/_images/GMT_anchor.png | ||
| :width: 600 px | ||
| :align: center |
There was a problem hiding this comment.
I feel we should make the images here and the one in the Technical References at https://pygmt-dev--4212.org.readthedocs.build/en/4212/techref/justification_codes.html consistent regarding the used colors.
There was a problem hiding this comment.
Here we use the image from the GMT documentation, mainly because it's technically difficult to generate an image dynamically in docstrings.
pygmt/params/position.py
Outdated
|
|
||
| **Reference Point** | ||
|
|
||
| The *reference point* can be specified in five different ways using the ``type`` and |
There was a problem hiding this comment.
I am unsure about type as attribute name, as type or type() seems to be a reserved keyword or function by Python itself:
We often use the name of a parameter or attribute for the name of the variable passed to the parameter or attribute:
import pygmt
from pygmt.params import Position
v = 5
# %%
type(v)
# works and outputs int
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
fig.logo(position=Position("TL", type="inside", offset="0.2c"), box=True)
fig.show()
# %%
type = "inside"
type(v)
# fails as function was overwritten
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
fig.logo(position=Position("TL", type=type, offset="0.2c"), box=True)
fig.show()There was a problem hiding this comment.
Yes, type is not an ideal name. Several options are:
coord_type: accurate but a little too longkind: a general term, similar totypecs_type: cs is short for "coordinate system", not that bad.
There was a problem hiding this comment.
I am fine with coord_type or cs_type. coord_type is more descriptive, but I have a slight preference for cs_type, as I feel for the arguments inside and outside "coordinate system" makes more sense. As geopandas uses crs for "coordinate reference systems", cs for "coordinate system" should be fine.
There was a problem hiding this comment.
Maybe cstype, since cs is already a shorthand for coordinate system?
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
See #4168 (comment) for context.
This PR implements the
Positionclass.Usage:
GMT Documentation: https://docs.generic-mapping-tools.org/dev/reference/features.html#reference-and-anchor-point-specification
Preview: https://pygmt-dev--4212.org.readthedocs.build/en/4212/api/generated/pygmt.params.Position.html