Skip to content

POC: Code PyGMT logo in PyGMT#3849

Draft
yvonnefroehlich wants to merge 350 commits intomainfrom
code-pygmt-logo
Draft

POC: Code PyGMT logo in PyGMT#3849
yvonnefroehlich wants to merge 350 commits intomainfrom
code-pygmt-logo

Conversation

@yvonnefroehlich
Copy link
Copy Markdown
Member

@yvonnefroehlich yvonnefroehlich commented Mar 13, 2025

Description of proposed changes

Related to #1404 (comment), create the PyGMT logo in Python with PyGMT.

  • Python script
  • Separat method Figure.pygmtlogo or Figure.logo_pygmt as part of the Figure class or addition to the method Figure.logo (which plots the GMT logo)
  • Gallery example

Preview:

Related to

TODO:

  • Update intro comment of this PR
  • Remove temporary files (eps)
  • Include adding a wordmark and it's orientation to the input at the beginning
  • Update codes to finale version of the visual
  • Introduce variables
  • Improve parameter names, e.g., shape="circle" | "hexagon" or hex=False | True
  • Convert to function (remove show and rdeuce save to tempoary eps files, replot via Figure.image)
  • Remove saving as eps file for rotation (first get ride of transparent margin)
  • Remove saving as eps file for adding wordmark (different basemaps due to horizontal and vertical orientation)
  • Convert to a method of the Figure class or addition to Figure.logo.
  • Add or expand gallery example to use the method
  • Explain the story behind the logo in the gallery example

Issues:

  • Get ride of white or transparent margin
  • Currently the rotation and adding the wordmark are done in new Figure objects using the saved eps files. Maybe this is not easy to handle when converting to a method of the Figure classe.
  • Decide about font for the wordmark (font Space Grotesk by Florian Karsten not available in GMT)
  • No direct export to SVG format possible
  • etc.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label Mar 13, 2025
@yvonnefroehlich yvonnefroehlich self-assigned this Mar 13, 2025
@yvonnefroehlich yvonnefroehlich changed the title Add first version of PyGMT code for PyGMT logo POC: DOC: Code PyGMT logo in PyGMT and add as gallery example Mar 13, 2025
@yvonnefroehlich
Copy link
Copy Markdown
Member Author

/format

@michaelgrund
Copy link
Copy Markdown
Member

michaelgrund commented Mar 13, 2025

I feel the logo definition should be separated into a standalone method, similar to the method to plot the GMT logo. This would allow to plot the PyGMT logo by calling something like pygmt.Figure.pygmt_logo. The individual formats could be selected by different input parameters like you did or hex = True or darkmode = True.

Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
@yvonnefroehlich yvonnefroehlich marked this pull request as draft March 13, 2025 13:27
@yvonnefroehlich yvonnefroehlich changed the title POC: DOC: Code PyGMT logo in PyGMT and add as gallery example POC: DOC: Code PyGMT logo in PyGMT (method Figure.pygmt_logo and gallery example) Mar 13, 2025
@yvonnefroehlich yvonnefroehlich added the feature Brand new feature label Mar 13, 2025
@yvonnefroehlich yvonnefroehlich changed the title POC: DOC: Code PyGMT logo in PyGMT (method Figure.pygmt_logo and gallery example) POC: Code PyGMT logo in PyGMT (method Figure.pygmt_logo and gallery example) Mar 13, 2025
@yvonnefroehlich yvonnefroehlich changed the title POC: Code PyGMT logo in PyGMT (method Figure.pygmt_logo and gallery example) POC: Code PyGMT logo in PyGMT (method or / and gallery example) Mar 13, 2025
@yvonnefroehlich
Copy link
Copy Markdown
Member Author

ruff v0.10.0 was released 2 hours ago causing the newly falling code style checks.

Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
@seisman seisman reopened this Mar 13, 2025
@yvonnefroehlich yvonnefroehlich changed the title POC: Code PyGMT logo in PyGMT (method or / and gallery example) POC: Code PyGMT logo in PyGMT Mar 14, 2025
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
@seisman
Copy link
Copy Markdown
Member

seisman commented Mar 16, 2025

  • separat method Figure.pygmtlogo or Figure.logo_pygmt as part of the Figure class or addition to the method Figure.logo (which plots the GMT logo)

@yvonnefroehlich You can follow the steps below:

  1. Create a pygmtlogo.py file under the pygmt/src/ directory
  2. Move the current pygmtlogo function to this file
  3. Add self as the first parameter of the pygmtlogo function
  4. Change fig.image (line 269) to self.image.
  5. Add from pygmt.src.pygmtlogo import pygmtlogo in pygmt/src/__init__.py
  6. Near line 429 in pygmt/figure.py, add pygmtlogo.

Then, you should be able to call Figure.pygmtlogo to add the logo.

yvonnefroehlich and others added 2 commits April 19, 2026 18:44
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
yvonnefroehlich and others added 8 commits April 20, 2026 13:02
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Comment thread pygmt/src/pygmtlogo.py Outdated
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
yvonnefroehlich and others added 2 commits April 20, 2026 17:25
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
yvonnefroehlich and others added 3 commits April 20, 2026 17:47
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Copy link
Copy Markdown
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions to add an inline example, and allow configuring the width/height. Still need to finalize the docstring (copy over from fig.image?).

Comment thread pygmt/src/pygmtlogo.py
color
Set to ``True`` to use colors referring to Python (blue and yellow) and GMT
(red) [Default]. For ``False``, the logo is drawn in black and white.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an inline example

Suggested change
"""
Examples
--------
>>> import pygmt
>>> fig = pygmt.Figure()
>>> fig.basemap(region=[-90, -70, 0, 20], projection="M10c", frame=True)
>>> fig.pygmtlogo(
... shape="circle",
... theme="light",
... wordmark="horizontal",
... color=True,
... position="BR",
... height="1c",
... )
>>> fig.show()
"""

Comment thread pygmt/src/pygmtlogo.py
Comment on lines +13 to +14

def create_logo( # noqa: PLR0915
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add __doctest_skip__ for inline example, and make _create_logo private function.

Suggested change
def create_logo( # noqa: PLR0915
__doctest_skip__ = ["pygmtlogo"]
def _create_logo( # noqa: PLR0915

Comment thread pygmt/src/pygmtlogo.py
# -----------------------------------------------------------------------------
# Create logo file
# -----------------------------------------------------------------------------
fig_name_logo = create_logo(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fig_name_logo = create_logo(
fig_name_logo = _create_logo(

Comment thread pygmt/src/pygmtlogo.py
theme="light",
shape="circle",
wordmark=True,
position=None, # -> Use position parameter of Figure.image
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow configuring width/height also

Suggested change
position=None, # -> Use position parameter of Figure.image
position=None, # -> Use position parameter of Figure.image
width=None, # -> Use width parameter of Figure.image
height=None, # -> Use height parameter of Figure.image

Comment thread pygmt/src/pygmtlogo.py
# -----------------------------------------------------------------------------
self.image(
imagefile=f"{fig_name_logo}.eps",
position=position,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=position,
position=position,
width=width,
height=height,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature Brand new feature

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants