Skip to content
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

POC: Code PyGMT logo in PyGMT #3849

Draft
wants to merge 132 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
2a319b7
Add first version of PyGMT code for PyGMT logo
yvonnefroehlich Mar 13, 2025
c4e683f
Remove execution permission
yvonnefroehlich Mar 13, 2025
0eb9044
Adjust tumbnail image
yvonnefroehlich Mar 13, 2025
4d2cc0e
Introduce input variable for adding wordmark and adjusting the orient…
yvonnefroehlich Mar 13, 2025
7c10e4a
Fix URL link
yvonnefroehlich Mar 13, 2025
135c4dc
Adjust saving (temp)
yvonnefroehlich Mar 13, 2025
8c6df7a
Adjust frame config
yvonnefroehlich Mar 13, 2025
11f230f
Remove execution permission
yvonnefroehlich Mar 13, 2025
dfd018a
Adjust length of diagonal lines
yvonnefroehlich Mar 13, 2025
a9e0503
Use corner for yellow line at right side of letter M
yvonnefroehlich Mar 13, 2025
c1679b3
Remove execution permission
yvonnefroehlich Mar 13, 2025
58cad71
Add space between horizontal line of letter G and letter M
yvonnefroehlich Mar 13, 2025
eb9c317
Add comment for distance between letters M and G
yvonnefroehlich Mar 13, 2025
5cc808e
Reduce white margin
yvonnefroehlich Mar 14, 2025
cdadee3
Remove execution permission
yvonnefroehlich Mar 14, 2025
6b91061
Add transparent option
yvonnefroehlich Mar 14, 2025
6a2e785
Remove execution permission
yvonnefroehlich Mar 14, 2025
9bbf443
Adjust yellow line ending at the right side of letter M
yvonnefroehlich Mar 14, 2025
945183b
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich Mar 14, 2025
0aea0b0
Make clean border of shape
yvonnefroehlich Mar 14, 2025
80b9a48
Remove execution permission
yvonnefroehlich Mar 14, 2025
591f724
Subpress temporary show | Add frame 0
yvonnefroehlich Mar 14, 2025
c75397d
Remove execution permission
yvonnefroehlich Mar 14, 2025
1fbb090
Introduce box parameter
yvonnefroehlich Mar 14, 2025
b1d373a
Fix code style | Improve box querry
yvonnefroehlich Mar 14, 2025
39e5ba1
Remove execution permission
yvonnefroehlich Mar 14, 2025
8519275
Update variable name
yvonnefroehlich Mar 14, 2025
71185ee
Remove execution permission
yvonnefroehlich Mar 14, 2025
57d91bd
Convert to function
yvonnefroehlich Mar 14, 2025
93c9f05
Fix code style and add examples
yvonnefroehlich Mar 14, 2025
7cfea09
Code formating
yvonnefroehlich Mar 14, 2025
e9d1798
Remove execution permission
yvonnefroehlich Mar 14, 2025
dab45b9
Update examples
yvonnefroehlich Mar 14, 2025
67b13be
Remove execution permission
yvonnefroehlich Mar 14, 2025
0fe36d3
Remove withe margin |Use box parameter of Figure.image
yvonnefroehlich Mar 14, 2025
5e19702
Follow coding style
yvonnefroehlich Mar 14, 2025
1d07537
Remove execution permission
yvonnefroehlich Mar 14, 2025
432d6cf
Minor updates | add examples
yvonnefroehlich Mar 14, 2025
725126d
Remove execution permission
yvonnefroehlich Mar 14, 2025
361e3aa
Remove unneeded docs
yvonnefroehlich Mar 14, 2025
9c9d19f
Remove unneeded parameters from examples
yvonnefroehlich Mar 14, 2025
9f1e812
Remove execution permission
yvonnefroehlich Mar 14, 2025
789d82e
Improve names of parameters
yvonnefroehlich Mar 14, 2025
b38edf9
Remove execution permission
yvonnefroehlich Mar 14, 2025
c8c7f79
Update parameter list explanaition
yvonnefroehlich Mar 14, 2025
ff04635
Remove execusion permission
yvonnefroehlich Mar 14, 2025
32c5341
Fix typo
yvonnefroehlich Mar 14, 2025
b079fd9
Fix rst syntax
yvonnefroehlich Mar 15, 2025
90a2890
Use variables for colors
yvonnefroehlich Mar 15, 2025
4c6013e
Introduce transpareny for wordmark
yvonnefroehlich Mar 15, 2025
f8ac7c0
Follow code style
yvonnefroehlich Mar 15, 2025
bdb6f14
Adjustments for tranparency for wordmark
yvonnefroehlich Mar 15, 2025
7416979
Remove execution permission
yvonnefroehlich Mar 15, 2025
ebdf4f2
Adjust example
yvonnefroehlich Mar 15, 2025
6d01ec1
Remove execution permission
yvonnefroehlich Mar 15, 2025
a60a88c
Add comment as reminder
yvonnefroehlich Mar 15, 2025
ec4583c
Remove execution permission
yvonnefroehlich Mar 15, 2025
4891de2
Combine box and bg_transparent to box parameter of Figure.image
yvonnefroehlich Mar 15, 2025
e3da0ce
Simplify code
yvonnefroehlich Mar 15, 2025
78872b4
Adjust outline
yvonnefroehlich Mar 15, 2025
470ed44
Try to use GMT color setting for font
yvonnefroehlich Mar 15, 2025
e77dde2
Remove unneeded code
yvonnefroehlich Mar 15, 2025
126a574
Remove execution permission
yvonnefroehlich Mar 15, 2025
5de8969
Polish code
yvonnefroehlich Mar 15, 2025
77c12f8
Follow code style
yvonnefroehlich Mar 15, 2025
76e1dac
Remove execution permission
yvonnefroehlich Mar 15, 2025
366970a
Use specific variable names
yvonnefroehlich Mar 15, 2025
43d6d92
Remove execution permission
yvonnefroehlich Mar 15, 2025
e401fea
Do rotation directly not eps export
yvonnefroehlich Mar 15, 2025
cbe6035
Remove execution permission
yvonnefroehlich Mar 15, 2025
e060bc7
Make full transparent
yvonnefroehlich Mar 15, 2025
d46d5e0
Use dicts
yvonnefroehlich Mar 15, 2025
cd38f53
Remove execution permission
yvonnefroehlich Mar 15, 2025
e8dd40c
Suppress code style fails because of to many statements PLR0915
yvonnefroehlich Mar 15, 2025
87dd5b7
Remove execution permission
yvonnefroehlich Mar 15, 2025
5f492d7
Add size of logo | add GMT in example | Polish code
yvonnefroehlich Mar 15, 2025
b8150a5
Follow code style
yvonnefroehlich Mar 15, 2025
8355de0
Plot yellow lines via loop over list
yvonnefroehlich Mar 15, 2025
7d382b0
Remove execution permission
yvonnefroehlich Mar 15, 2025
ff512cc
Plot red lines for letter M via loop over list
yvonnefroehlich Mar 15, 2025
c072743
Adjust variable name
yvonnefroehlich Mar 15, 2025
5962954
Use dict
yvonnefroehlich Mar 15, 2025
5175a28
Reduce number of branches to be not > 12
yvonnefroehlich Mar 15, 2025
3768a06
Remove execution permission
yvonnefroehlich Mar 15, 2025
433f8e4
Improve comments
yvonnefroehlich Mar 15, 2025
479f4a2
Remove execution permission
yvonnefroehlich Mar 15, 2025
4f9ae6f
Do not rotate initial basemap -> no need of resize in savefig
yvonnefroehlich Mar 15, 2025
08c7e56
Follow code style
yvonnefroehlich Mar 15, 2025
8cb9079
Remove execution permission
yvonnefroehlich Mar 15, 2025
d2f479d
No temp eps file for wordmark
yvonnefroehlich Mar 15, 2025
f304d49
Adjust position and font size for wordmark based on orientation
yvonnefroehlich Mar 15, 2025
f7a84c5
Follow code style
yvonnefroehlich Mar 15, 2025
b18f816
Comment code
yvonnefroehlich Mar 15, 2025
5ff52a8
Remove execution permission
yvonnefroehlich Mar 15, 2025
9297ac5
Adjust position of wordmark
yvonnefroehlich Mar 15, 2025
50e361b
Remove execution permission
yvonnefroehlich Mar 15, 2025
09471e8
Create pygmtlogo.py in src and move code
yvonnefroehlich Mar 16, 2025
0a35459
Update __init__.py
yvonnefroehlich Mar 16, 2025
b4259ad
Update figure.py
yvonnefroehlich Mar 16, 2025
06fbfbd
Update gallery exampel
yvonnefroehlich Mar 16, 2025
c9c9d75
Add Docstrings
yvonnefroehlich Mar 16, 2025
efff204
Fix import in Gallery example
yvonnefroehlich Mar 16, 2025
7779832
Update index
yvonnefroehlich Mar 16, 2025
79500dd
Update gallery example
yvonnefroehlich Mar 16, 2025
7f9d57e
Update imports
yvonnefroehlich Mar 16, 2025
2132e5e
Add tests
yvonnefroehlich Mar 16, 2025
438a100
Follow code style
yvonnefroehlich Mar 16, 2025
cb854e3
Update docs
yvonnefroehlich Mar 16, 2025
3d40b6a
Remove exectuion permission
yvonnefroehlich Mar 16, 2025
d81c077
Remove exection permission
yvonnefroehlich Mar 16, 2025
2696234
Remove execution permission
yvonnefroehlich Mar 16, 2025
c9262cc
Update docstrings
yvonnefroehlich Mar 16, 2025
5999c51
Follow rules for variable names and use no space between consonants
yvonnefroehlich Mar 16, 2025
4121569
Reduce galler example
yvonnefroehlich Mar 16, 2025
16eb3dc
Expand tests
yvonnefroehlich Mar 16, 2025
6d71dc3
Set box default to None
yvonnefroehlich Mar 17, 2025
e8c693e
Plot without setting up basemap
yvonnefroehlich Mar 17, 2025
dcc38e1
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich Mar 17, 2025
1a2ca98
Add more parameters
yvonnefroehlich Mar 17, 2025
d716bd5
Exclude PLR0913
yvonnefroehlich Mar 17, 2025
59dff81
Update tests
yvonnefroehlich Mar 17, 2025
d35c445
Use default position=Non
yvonnefroehlich Mar 18, 2025
13306c8
Remove blank line
yvonnefroehlich Mar 18, 2025
78ea05a
Move function create_logo out of function pygmtlogo
yvonnefroehlich Mar 18, 2025
7910e05
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich Mar 18, 2025
6ec39e7
Adjust defaults
yvonnefroehlich Mar 20, 2025
787530d
Update gallery example
yvonnefroehlich Mar 20, 2025
7601e93
Fix typo
yvonnefroehlich Mar 20, 2025
ec13d17
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich Mar 20, 2025
1f1bfd9
Adjust gallery example
yvonnefroehlich Mar 21, 2025
1b51c05
Adjust docstring
yvonnefroehlich Mar 21, 2025
ebcf510
Fix typo
yvonnefroehlich Mar 21, 2025
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
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Plotting map elements
Figure.inset
Figure.legend
Figure.logo
Figure.pygmtlogo
Figure.solar
Figure.text
Figure.timestamp
Expand Down
47 changes: 47 additions & 0 deletions examples/gallery/embellishments/pygmt_logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
PyGMT logo
==========
The PyGMT logo coded in Python using PyGMT. The design of the logo is kindly provided
by `@sfrooti <https://github.com/sfrooti>`_. The logo consists of a visual and the
wordmark "PyGMT".
"""

import pygmt

fig = pygmt.Figure()
fig.pygmtlogo()
fig.show()

# %%

fig = pygmt.Figure()
fig.pygmtlogo(darkmode=True, box="+ggray20")
fig.show()

# %%

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X10c", frame=[1, "+gtan"])

fig.pygmtlogo(position="jTL+o0.2c+w4c", box="+gwhite+p1p,gray")
fig.pygmtlogo(hexshape=True, position="jTR+o0.2c+w4c")

fig.pygmtlogo(
blackwhite=True,
wordmark=False,
position="jTL+o0.5c/2c+w1.5c",
box=False,
)
fig.pygmtlogo(
blackwhite=True,
darkmode=True,
hexshape=True,
wordmark=False,
position="jTR+o0.5c/2c+w1.5c",
box=False,
)
fig.pygmtlogo(orientation="vertical", position="jMC+w2c")

fig.show()

# sphinx_gallery_thumbnail_number = 3
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def _repr_html_(self) -> str:
plot,
plot3d,
psconvert,
pygmtlogo,
rose,
set_panel,
shift_origin,
Expand Down
1 change: 1 addition & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pygmt.src.plot3d import plot3d
from pygmt.src.project import project
from pygmt.src.psconvert import psconvert
from pygmt.src.pygmtlogo import pygmtlogo
from pygmt.src.rose import rose
from pygmt.src.select import select
from pygmt.src.shift_origin import shift_origin
Expand Down
295 changes: 295 additions & 0 deletions pygmt/src/pygmtlogo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
"""
pygmtlogo - Create and plot the PyGMT logo.
The design of the logo is kindly provided by `@sfrooti <https://github.com/sfrooti>`_.
"""

from pathlib import Path

import pygmt


def create_logo( # noqa: PLR0915
blackwhite=False,
darkmode=False,
hexshape=False,
wordmark=True,
orientation="horizontal",
):
Comment on lines +11 to +17
Copy link
Member

Choose a reason for hiding this comment

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

For the parameters, what about:

  • color: True or color or False for black/white
  • theme: "light" or "dark"
  • shape: "circle" or "hex"
  • wordmark: True/False/"horizontal"/"vertical" [True means "horizontal"].

"""
Creat the PyGMT logo.
The design of the logo is kindly provided by `@sfrooti <https://github.com/sfrooti>`_.

Parameters
----------

blackwhite : bool
Draw in black and white. Set to ``True`` for black and white [Default is
``False`` and uses colors for Python (blue and yellow) and GMT (red)].
darkmode : bool
Use dark mode. Set to``True`` for dark mode [Default is ``False`` for light
mode].
hexshape : bool
Use a hexagon shape. Set to ``True`` for a hexagon shape [Default is `False``
and uses to a circle shape].
wordmark : bool
Add the wordmark "PyGMT". Set to `True`` to add the wordmark [Default]. For
``False`` no wordmark is added.
orientation : str
Orientation of the wordmark. Use ``"horizontal"`` to place the wordmark at
the right side [Default] or ``"vertical"`` to place it below the visual.
"""

# -----------------------------------------------------------------------------
# Helpful definitions
# -----------------------------------------------------------------------------
size = 4
region = [-size, size] * 2

xy_yellow_1 = 2.65
xy_yellow_2 = 1.3

no_line = "cyan@100"
no_fill = f"+g{no_line}"

# Rotation around z (vertical) axis placed in the center
# Has to be applied to each plotting command, up on second call set to True
# Do NOT rotated initial basemap
angle_rot = 30 # degrees
perspective = f"{angle_rot}+w0/0"

# -----------------------------------------------------------------------------
# Define colors
# -----------------------------------------------------------------------------
color_dark = "gray20"
color_light = "white"

# visual
color_blue = "48/105/152" # Python blue
color_yellow = "255/212/59" # Python yellow
color_red = "238/86/52" # GMT red
if blackwhite:
color_blue = color_yellow = color_red = color_light
if not darkmode:
color_blue = color_yellow = color_red = color_dark

Check warning on line 73 in pygmt/src/pygmtlogo.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/pygmtlogo.py#L71-L73

Added lines #L71 - L73 were not covered by tests

# background and wordmark
color_bg = color_dark
color_py = color_yellow
color_gmt = color_light
if not darkmode:
color_bg = color_light
color_py = color_blue
color_gmt = color_dark

# -----------------------------------------------------------------------------
# Define shape
# -----------------------------------------------------------------------------
symbol = "c" # circle
diameter = 7.5
diameter_add = 0.5
if hexshape:
symbol = "h" # hexagon
diameter = 8.6
diameter_add = 0.6

Check warning on line 93 in pygmt/src/pygmtlogo.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/pygmtlogo.py#L91-L93

Added lines #L91 - L93 were not covered by tests

# -----------------------------------------------------------------------------
# Define wordmark
# -----------------------------------------------------------------------------
font = "AvantGarde-Book"
match orientation:
case "vertical":
args_text_wm = {
"x": 0,
"y": -5,
"justify": "CT",
"font": f"2.5c,{font}",
}
case "horizontal":
args_text_wm = {
"x": 6,
"y": 0,
"justify": "LM",
"font": f"8c,{font}",
}

# -----------------------------------------------------------------------------
# Start plotting
# -----------------------------------------------------------------------------
fig = pygmt.Figure()
pygmt.config(MAP_FRAME_PEN=no_line)
fig.basemap(
region=region,
projection=f"X{size * 2}c",
frame=no_fill,
)

# .............................................................................
# blue circle / hexagon for Earth
# .............................................................................
fig.plot(
x=0,
y=0,
style=f"{symbol}{diameter}c",
pen=f"15p,{color_blue}",
fill=color_bg,
no_clip=True,
perspective=perspective,
)

# .............................................................................
# yellow lines for compass
# .............................................................................
args_yellow = {"pen": f"5p,{color_yellow}", "perspective": True}
# horizontal yellow line
fig.plot(x=[-4, 4], y=[0, 0], no_clip=True, **args_yellow)
# diagonal yellow lines
lines_diagonal = [
([-xy_yellow_1, -xy_yellow_2], [xy_yellow_1, xy_yellow_2]), # upper left
([xy_yellow_2, xy_yellow_1], [-xy_yellow_2, -xy_yellow_1]), # lower right
([-xy_yellow_1, -xy_yellow_2], [-xy_yellow_1, -xy_yellow_2]), # lower left
([xy_yellow_2, xy_yellow_1], [xy_yellow_2, xy_yellow_1]), # upper right
]
for x_coords, y_coords in lines_diagonal:
fig.plot(x=x_coords, y=y_coords, **args_yellow)

# .............................................................................
# letter G
# .............................................................................
# horizontal red line
fig.plot(x=[0.1, 1.65], y=[0, 0], pen=f"12p,{color_red}", perspective=True)
# red ring sector
fig.plot(x=0, y=0, style="w3.3c/90/0+i2.35c", fill=color_red, perspective=True)
# space between yellow lines and ring sector
fig.plot(x=0, y=0, style="w3.7c/0/360+i3.3c", fill=color_bg, perspective=True)
# vertical yellow line
fig.plot(x=[0, 0], y=[-4, 4], pen=f"6p,{color_yellow}", perspective=True)
# cover yellow line in lower part of the ring sector
fig.plot(x=0, y=0, style="w3.3c/260/-80+i2.35c", fill=color_red, perspective=True)

# .............................................................................
# upper vertical red line
# .............................................................................
# space between red line and blue circle / hexagon
fig.plot(x=[0, 0], y=[4, 3.0], pen=f"18p,{color_bg}", perspective=True)
# red line
fig.plot(x=[0, 0], y=[4, 1.9], pen=f"12p,{color_red}", perspective=True)

# .............................................................................
# letter M
# .............................................................................
# space between letter M and yellow line at the right side
# fig.plot(x=[1.6, 1.6], y=[1.5, 1.775], pen=f"10p,{color_bg}")
fig.plot(x=[1.6, 1.6], y=[1.5, 2.0], pen=f"10p,{color_bg}", perspective=True)
# lines with small distance to horizontal line of letter G
args_m = {"pen": f"10p,{color_red}", "perspective": True}
lines_m = [
([0.33, 0.90], [1.527, 1.00]), # diagonal left
([0.90, 1.43], [1.00, 1.527]), # diagonal right
([0.285, 0.285], [0.30, 1.65]), # vertical left
([1.47, 1.47], [0.30, 1.65]), # vertical right
]
for x_coords, y_coords in lines_m:
fig.plot(x=x_coords, y=y_coords, **args_m)
# middle corner
fig.plot(x=0.9, y=0.9, style="d0.3c", fill=color_red, perspective=True)

# .............................................................................
# letter T
# .............................................................................
# red curved horizontal line
fig.plot(x=0, y=0, style="w4.6c/240/-60+i3.7c", fill=color_red, perspective=True)
# vertical endings of curved horizontal line
args_vert = {"y": [-1.5, -2.5], "pen": f"9p,{color_bg}", "perspective": True}
fig.plot(x=[-1.05, -1.05], **args_vert)
fig.plot(x=[1.05, 1.05], **args_vert)
# arrow head as inverse triangle with pen for space to blue circle / hexagon
fig.plot(
x=0,
y=-3.55,
style="i1.1c",
fill=color_red,
pen=f"3p,{color_bg}",
perspective=True,
)
# arrow tail
fig.plot(x=[0, 0], y=[-2, -3.57], pen=f"12p,{color_red}", perspective=True)

# margin around shape for blackwhite=True in darkmode=True
if blackwhite and darkmode:
fig.plot(

Check warning on line 219 in pygmt/src/pygmtlogo.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/pygmtlogo.py#L219

Added line #L219 was not covered by tests
x=0,
y=0,
style=f"{symbol}{diameter + diameter_add}c",
pen=f"1p,{color_dark}",
no_clip=True,
perspective=True,
)

# .............................................................................
# Add wordmark "PyGMT"
# .............................................................................
if wordmark:
text_wm = f"@;{color_py};Py@;;@;{color_gmt};GMT@;;"
fig.text(text=text_wm, no_clip=True, **args_text_wm)

# .............................................................................
# Save
# .............................................................................
fig_name_logo = "pygmt_logo"
fig.savefig(fname=f"{fig_name_logo}.eps")

return fig_name_logo, color_bg


def pygmtlogo( # noqa: PLR0913
self,
blackwhite=False,
darkmode=False,
hexshape=False,
wordmark=True,
orientation="horizontal",
position=None, # -> use position parameter of Figure.image
box=None, # -> use box parameter of Figure.image
projection=None,
region=None,
verbose=None,
panel=None,
transparency=None,
):
"""
Plot the PyGMT logo.
The design of the logo is kindly provided by `@sfrooti <https://github.com/sfrooti>`_.
"""

# -----------------------------------------------------------------------------
# Create logo file
# -----------------------------------------------------------------------------
fig_name_logo, color_bg = create_logo(
blackwhite=blackwhite,
darkmode=darkmode,
hexshape=hexshape,
wordmark=wordmark,
orientation=orientation,
)

# -----------------------------------------------------------------------------
# Add box around logo
# -----------------------------------------------------------------------------
# if box is None:
# box = f"+g{color_bg}"

# -----------------------------------------------------------------------------
# Add to existing Figure instance
# -----------------------------------------------------------------------------
self.image(
imagefile=f"{fig_name_logo}.eps",
position=position,
box=box,
projection=projection,
region=region,
verbose=verbose,
panel=panel,
transparency=transparency,
)

Path.unlink(f"{fig_name_logo}.eps")
Loading
Loading