Skip to content

WIP: Code PyGMT logo in PyGMT#3849

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

WIP: Code PyGMT logo in PyGMT#3849
yvonnefroehlich wants to merge 390 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
  • Separate 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)
  • Documentation
  • Tests
  • Gallery example -> separate PR

Related to

Preview:
https://pygmt-dev--3849.org.readthedocs.build/en/3849/api/generated/pygmt.Figure.pygmtlogo.html

image image image image
image image image image
image image image image

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.

Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread examples/gallery/embellishments/pygmt_logo.py Outdated
@yvonnefroehlich
Copy link
Copy Markdown
Member Author

The commit history is so long that it's really painful to find any old comments...

Oh, yes!! I already started making a list of still relevant review comments 😅.

Comment thread pygmt/src/pygmtlogo.py Outdated
@seisman
Copy link
Copy Markdown
Member

seisman commented Apr 21, 2026

The commit history is so long that it's really painful to find any old comments...

Oh, yes!! I already started making a list of still relevant review comments 😅.

I wonder if we should merge this PR into a separate branch (not main) and then open a separate PR. In this way, we would have much cleaner commit history.

Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py Outdated
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
@yvonnefroehlich
Copy link
Copy Markdown
Member Author

I think the colored circular version is already very good now, and we should add a test and baseline image for it, so that any further changes don't break it suddently.

Agree, we should focus on the circular version for now. The hexagon version would be nice to have and hex stickers seem to be quite popular. But the hexagon shape makes things so much more (too) complicated and it is difficult to implement things based on calculation rather than on empircal factors. Furthuremore only the circular version directly has the relation to the Earth.

I wonder if we should merge this PR into a separate branch (not main) and then open a separate PR. In this way, we would have much cleaner commit history.

Joa, we can try this. Should test and baseline image added before?

@seisman
Copy link
Copy Markdown
Member

seisman commented Apr 21, 2026

Should test and baseline image added before?

I think yes

@yvonnefroehlich yvonnefroehlich changed the title POC: Code PyGMT logo in PyGMT WIP: Code PyGMT logo in PyGMT Apr 21, 2026
@yvonnefroehlich
Copy link
Copy Markdown
Member Author

I removed the script for the gallery example. I think we should add it in a separate PR. And the current version was not really a gallery example, but a summary of all versions of the logo.

Copy link
Copy Markdown
Member Author

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

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

Maybe we can combine some of the tests into one test to have less baseline images.

@seisman
Copy link
Copy Markdown
Member

seisman commented Apr 22, 2026

Maybe we can combine some of the tests into one test to have less baseline images.

I think so. Maybe we can start with a test including the following two logos:

image

@seisman
Copy link
Copy Markdown
Member

seisman commented Apr 22, 2026

I wonder if we should merge this PR into a separate branch (not main) and then open a separate PR. In this way, we would have much cleaner commit history.

Joa, we can try this.

I've created the pygmtlogo branch. I think we can change the base branch of this PR to pygmtlogo, then merge this PR after you add the tests and baseline images.

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
Comment thread pygmt/src/pygmtlogo.py
def _create_logo( # noqa: PLR0915
shape: Literal["circle", "hexagon"] = "circle",
theme: Literal["light", "dark"] = "light",
wordmark: Literal["horizontal", "vertical"] | bool = True,
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.

I wonder if it makes more sense to have wordmark default to False.

Comment thread pygmt/src/pygmtlogo.py Outdated
Comment on lines +35 to +39
thick_shape = r0 - r1 # for shape
thick_gt = r4 - r5 # for letters G and T
thick_m = r4 / 5 # for letter M
thick_comp = thick_shape / 3 # for compass lines
thick_gap = (thick_comp / 4) * 3
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.

If we ignore the factor size/256, currently, the thicknesses are:

thick_shape = r0 - r1 = 74
thick_gt = r4 - r5 = 28
thick_m = r4 / 5 = 21.2
thick_comp = 74/3=24.666666
thick_gap = 18.5

I wonder if we could slightly change the radii so that all the above values are integers.

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
Comment thread pygmt/src/pygmtlogo.py Outdated
Comment thread pygmt/src/pygmtlogo.py
Comment on lines +248 to +251
fig_name_logo = "pygmt_logo"
fig.savefig(fname=f"{fig_name_logo}.eps")

return fig_name_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.

It's not ideal to hardcode the eps file name in this function. Instead, the pygmtlogo function should use GMTTempoaryFile and pass a tempoary file name to this function.

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 6 commits April 22, 2026 18:22
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
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