-
Notifications
You must be signed in to change notification settings - Fork 234
Figure.logo: Add parameters position/width/height to specify logo position and dimensions #4014
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
Merged
+228
−28
Merged
Changes from all commits
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
fb64cbf
Figure.logo: Refactor using the AliasSystem class
seisman 1eb6587
Update position_type
seisman 6fa17ac
Updates
seisman cb40511
Merge branch 'main' into refactor/logo
seisman 6edab47
Merge branch 'main' into refactor/logo
seisman cd1165f
fix
seisman dab0bdb
Merge branch 'main' into refactor/logo
seisman 494afc5
Merge branch 'main' into refactor/logo
seisman b17ecfe
Remove D from use_alias
seisman 6ec9c66
Fix typos
seisman 9307150
Merge branch 'main' into refactor/logo
seisman 9a0575d
Improve docstrings
seisman d19959e
Improve docstrings
seisman df0aba0
Merge branch 'main' into refactor/logo
seisman f8f418b
Backward compatibility
seisman df50342
Improve Figure.logo tests
seisman 6bd1dc2
Merge branch 'main' into refactor/logo
seisman 8699d9a
Add a test for mixed syntax
seisman 2f09ee9
Merge branch 'main' into refactor/logo
seisman da38bd1
Merge branch 'main' into refactor/logo
seisman 5e02d22
Update docstrings
seisman 7568264
Fix formatting
seisman 43d08a0
Fix docstrings
seisman 91b6b25
Fix long docstrings
seisman 4f61e2e
Merge branch 'main' into refactor/logo
seisman 6d3dc9b
Fix docstrings
seisman 62e6274
Fix docstrings
seisman e3d14d5
Fix docstrings
seisman e73dc9e
Fix comments
seisman e77993b
Fix docstrings
seisman 66f9c4d
Fix docstrings
seisman a33bf5d
Merge branch 'main' into refactor/logo
seisman fb95478
Fix offset to anchor_offset in the Figure.inset doctest
seisman 9ca90fb
Merge remote-tracking branch 'origin/refactor/logo' into refactor/logo
seisman 51fe976
Improve the handling of deprecation position parameter
seisman 71bc7cc
Merge branch 'main' into refactor/logo
seisman f22afc1
Merge branch 'main' into refactor/logo
seisman 5027a41
Merge branch 'main' into refactor/logo
seisman 573e950
Fix docstrings in tests
seisman 173e7a4
Shorten the docstrings
seisman 92d8b08
Merge branch 'main' into refactor/logo
seisman eec0fb7
Initial implemention of the Position class
seisman 69d4d42
Merge branch 'main' into params/position
seisman 539f66f
Fix styling
seisman 97f015f
Add tests and improve docstrings
seisman 854804e
Add to API doc
seisman 6b55dde
Add an inline doctest
seisman 3d629cb
position is not required
seisman 576b822
Default to plotcoords
seisman f54bec9
Updates
seisman 5a2e20b
Merge branch 'main' into params/position
seisman 2c59b7f
Improve the checking in Figure.logo
seisman d0b62ec
Merge branch 'main' into params/position
seisman fe18c87
Improve docstrings
seisman 038161b
Improve docstrings
seisman a6e75bc
Improve docstrings
seisman 3ec8c06
Improve docstrings
seisman 339ce00
Improve docstrings
seisman 4d616de
Revert changes in logo.py
seisman ad9e0aa
Simplify tests
seisman b084e5f
Validate values
seisman d4ad6e0
type will be validated in the Alias System
seisman 7dc37bd
Use the image from the GMT docs
seisman bfecb2d
Fix width and alignment
seisman f49d4db
Merge branch 'params/position' into refactor/logo
seisman 9f2cafd
Refactor Figure.logo using the Position class
seisman 026e583
Remove some tests
seisman e9dd1e0
Update examples/gallery/embellishments/gmt_logo.py
seisman 18b90b3
Improve docstrings
seisman 6b1b5bc
Remove unneeded blank lines
seisman 1eae742
Improve docstrings
seisman 721b46f
Validate anchor code
seisman 669b16d
Merge branch 'main' into params/position
seisman 2a38111
Merge branch 'main' into params/position
seisman 0f9ed6c
offset can be a single value
seisman 7d1b076
Merge branch 'main' into params/position
seisman a779431
Merge branch 'main' into params/position
seisman 2a9cc92
Merge branch 'main' into params/position
seisman 10a0dfb
Use is_nonstr_iter to check the location parameter
seisman 6f1c2c4
Merge remote-tracking branch 'origin/params/position' into params/pos…
seisman c27213f
Fix a typo [skip ci]
seisman d47aaeb
Fix a typo [skip ci]
seisman 7fc6ffc
Fix the wrong logic in checking location
seisman d82f4ba
Add a tests for passing a single value to offset
seisman 5d29e66
Merge branch 'main' into params/position
seisman 563b5a1
Merge branch 'main' into params/position
seisman 02d8713
Add the Axes, Axis, Frame classes for the frame parameter
seisman 6f97c57
Add to API documentation
seisman b2c9877
Improve Axis/Axes/Frame and add more tests
seisman 0ec021b
Merge branch 'main' into params/position
seisman 42dede8
Merge branch 'AliasSystem/params/frame' into refactor/logo
seisman 708eeac
Revert "Improve Axis/Axes/Frame and add more tests"
seisman e30969e
Revert "Add to API documentation"
seisman 353a73d
Revert "Add the Axes, Axis, Frame classes for the frame parameter"
seisman f254da2
Merge remote-tracking branch 'origin/params/position' into refactor/logo
seisman 238eb2e
Fix an inline doctest
seisman d2ed7b7
Improve the import in examples/gallery/embellishments/gmt_logo.py
seisman 9e9c0d6
Fix the inline doctest in inset
seisman 271af68
Reorder parameters
seisman ff23ac8
Merge branch 'main' into params/position
seisman c9c4222
Rename position to refpoint
seisman 0064cde
Fix formatting
seisman bd223e2
Use any() to simplify codes
seisman 97a13f1
Improve error message
seisman 90c7ea2
Merge branch 'main' into params/position
seisman 91b5630
r-string is not required
seisman 9a19c1a
Merge branch 'main' into params/position
seisman ff6392d
Update pygmt/params/position.py
seisman 2310b22
Update pygmt/params/position.py [skip ci]
seisman a3185e8
Fix styling
seisman e153ebf
Rename type to cstype
seisman ed31e0f
Merge branch 'main' into params/position
seisman fe5c47a
Fix type to cstype
seisman 8e75634
Merge branch 'params/position' into refactor/logo
seisman eaa0a50
Merge branch 'main' into refactor/logo
seisman 3a48d4d
cstype="inside" is the default
seisman f50921b
Merge branch 'main' into refactor/logo
seisman 066e471
Merge branch 'main' into refactor/logo
seisman a69b6ea
Merge branch 'main' into refactor/logo
seisman 630c607
Merge branch 'main' into refactor/logo
seisman 2695008
Merge branch 'main' into refactor/logo
seisman 5c2ce9f
Default position is (0, 0)
seisman 5aea9d3
Reorder a few parameters
seisman cbe9250
Improve docstrings
seisman d815f33
Add a baseline image
seisman 7ea587f
Fix test_logo_default_position
seisman 9b7f0f5
Allow shortcuts for positions
seisman fbe74ed
Fix typing and improve docstrings
seisman 183a7a6
improve docstrings
seisman 838ccc4
Merge branch 'main' into refactor/logo
seisman 7b69695
Rename default_position to default and improve docstrings
seisman 63fe973
Make 'default' optional
seisman d0a34a5
Improve docstrings in _parse_position
seisman ef750b5
Fix a typo [skip ci]
seisman 295de16
Merge branch 'main' into refactor/logo
seisman 77bec8e
Merge branch 'main' into refactor/logo
seisman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,38 +5,51 @@ | |
| from collections.abc import Sequence | ||
| from typing import Literal | ||
|
|
||
| from pygmt._typing import AnchorCode | ||
| from pygmt.alias import Alias, AliasSystem | ||
| from pygmt.clib import Session | ||
| from pygmt.helpers import build_arg_list, fmt_docstring, use_alias | ||
| from pygmt.params import Box | ||
| from pygmt.exceptions import GMTInvalidInput | ||
| from pygmt.helpers import build_arg_list, fmt_docstring | ||
| from pygmt.params import Box, Position | ||
| from pygmt.src._common import _parse_position | ||
|
|
||
|
|
||
| @fmt_docstring | ||
| @use_alias(D="position") | ||
| def logo( | ||
| def logo( # noqa: PLR0913 | ||
| self, | ||
| position: Position | Sequence[float | str] | AnchorCode | None = None, | ||
| width: float | str | None = None, | ||
| height: float | str | None = None, | ||
| box: Box | bool = False, | ||
| style: Literal["standard", "url", "no_label"] = "standard", | ||
| projection: str | None = None, | ||
| region: Sequence[float | str] | str | None = None, | ||
| style: Literal["standard", "url", "no_label"] = "standard", | ||
| box: Box | bool = False, | ||
| verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | ||
| | bool = False, | ||
| panel: int | Sequence[int] | bool = False, | ||
| transparency: float | None = None, | ||
| perspective: float | Sequence[float] | str | bool = False, | ||
| transparency: float | None = None, | ||
| **kwargs, | ||
| ): | ||
| r""" | ||
| """ | ||
| Plot the GMT logo. | ||
|
|
||
| By default, the GMT logo is 2 inches wide and 1 inch high and | ||
| will be positioned relative to the current plot origin. | ||
| Use various options to change this and to place a transparent or | ||
| opaque rectangular map panel behind the GMT logo. | ||
| .. figure:: https://docs.generic-mapping-tools.org/6.6/_images/GMT_coverlogo.png | ||
| :alt: GMT logo | ||
| :align: center | ||
| :width: 300px | ||
|
|
||
| By default, the GMT logo is 2 inches wide and 1 inch high and will be positioned | ||
| relative to the current plot origin. | ||
|
|
||
| Full GMT docs at :gmt-docs:`gmtlogo.html`. | ||
|
|
||
| $aliases | ||
| **Aliases:** | ||
|
|
||
| .. hlist:: | ||
| :columns: 3 | ||
|
|
||
| - D = position, **+w**: width, **+h**: height | ||
| - F = box | ||
| - J = projection | ||
| - R = region | ||
|
|
@@ -48,12 +61,22 @@ def logo( | |
|
|
||
| Parameters | ||
| ---------- | ||
| $projection | ||
| $region | ||
| position : str | ||
| [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ | ||
| **+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]]. | ||
| Set reference point on the map for the image. | ||
| position | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented in 9b7f0f5. |
||
| Position of the GMT logo on the plot. It can be specified in multiple ways: | ||
|
|
||
| - A :class:`pygmt.params.Position` object to fully control the reference point, | ||
| anchor point, and offset. | ||
| - A sequence of two values representing the x and y coordinates in plot | ||
| coordinates, e.g., ``(1, 2)`` or ``("1c", "2c")``. | ||
| - A :doc:`2-character justification code </techref/justification_codes>` for a | ||
| position inside the plot, e.g., ``"TL"`` for Top Left corner inside the plot. | ||
|
|
||
| If not specified, defaults to the lower-left corner of the plot (position | ||
| ``(0, 0)`` with anchor ``"BL"``). | ||
| width | ||
| height | ||
| Width or height of the GMT logo. Since the aspect ratio is fixed, only one of | ||
| the two can be specified. [Default is 2 inches wide and 1 inch high]. | ||
| box | ||
| Draw a background box behind the logo. If set to ``True``, a simple rectangular | ||
| box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box appearance, | ||
|
|
@@ -65,14 +88,32 @@ def logo( | |
| - ``"standard"``: The text label "The Generic Mapping Tools". | ||
| - ``"no_label"``: Skip the text label. | ||
| - ``"url"``: The URL to the GMT website. | ||
| $projection | ||
| $region | ||
| $verbose | ||
| $panel | ||
| $transparency | ||
| $perspective | ||
| $transparency | ||
| """ | ||
| self._activate_figure() | ||
|
|
||
| position = _parse_position( | ||
| position, | ||
| kwdict={"width": width, "height": height}, | ||
| default=Position((0, 0), cstype="plotcoords"), # Default to (0,0) in plotcoords | ||
| ) | ||
|
|
||
| # width and height are mutually exclusive. | ||
| if width is not None and height is not None: | ||
| msg = "Cannot specify both 'width' and 'height'." | ||
| raise GMTInvalidInput(msg) | ||
|
|
||
| aliasdict = AliasSystem( | ||
| D=[ | ||
| Alias(position, name="position"), | ||
| Alias(height, name="height", prefix="+h"), | ||
| Alias(width, name="width", prefix="+w"), | ||
| ], | ||
| F=Alias(box, name="box"), | ||
| S=Alias( | ||
| style, name="style", mapping={"standard": "l", "url": "u", "no_label": "n"} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: 6fa301eb7cd0e467285160cf261f9a10 | ||
| size: 44372 | ||
| hash: md5 | ||
| path: test_logo_default_position.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.