-
Notifications
You must be signed in to change notification settings - Fork 228
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
yvonnefroehlich
wants to merge
132
commits into
main
Choose a base branch
from
code-pygmt-logo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 c4e683f
Remove execution permission
yvonnefroehlich 0eb9044
Adjust tumbnail image
yvonnefroehlich 4d2cc0e
Introduce input variable for adding wordmark and adjusting the orient…
yvonnefroehlich 7c10e4a
Fix URL link
yvonnefroehlich 135c4dc
Adjust saving (temp)
yvonnefroehlich 8c6df7a
Adjust frame config
yvonnefroehlich 11f230f
Remove execution permission
yvonnefroehlich dfd018a
Adjust length of diagonal lines
yvonnefroehlich a9e0503
Use corner for yellow line at right side of letter M
yvonnefroehlich c1679b3
Remove execution permission
yvonnefroehlich 58cad71
Add space between horizontal line of letter G and letter M
yvonnefroehlich eb9c317
Add comment for distance between letters M and G
yvonnefroehlich 5cc808e
Reduce white margin
yvonnefroehlich cdadee3
Remove execution permission
yvonnefroehlich 6b91061
Add transparent option
yvonnefroehlich 6a2e785
Remove execution permission
yvonnefroehlich 9bbf443
Adjust yellow line ending at the right side of letter M
yvonnefroehlich 945183b
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 0aea0b0
Make clean border of shape
yvonnefroehlich 80b9a48
Remove execution permission
yvonnefroehlich 591f724
Subpress temporary show | Add frame 0
yvonnefroehlich c75397d
Remove execution permission
yvonnefroehlich 1fbb090
Introduce box parameter
yvonnefroehlich b1d373a
Fix code style | Improve box querry
yvonnefroehlich 39e5ba1
Remove execution permission
yvonnefroehlich 8519275
Update variable name
yvonnefroehlich 71185ee
Remove execution permission
yvonnefroehlich 57d91bd
Convert to function
yvonnefroehlich 93c9f05
Fix code style and add examples
yvonnefroehlich 7cfea09
Code formating
yvonnefroehlich e9d1798
Remove execution permission
yvonnefroehlich dab45b9
Update examples
yvonnefroehlich 67b13be
Remove execution permission
yvonnefroehlich 0fe36d3
Remove withe margin |Use box parameter of Figure.image
yvonnefroehlich 5e19702
Follow coding style
yvonnefroehlich 1d07537
Remove execution permission
yvonnefroehlich 432d6cf
Minor updates | add examples
yvonnefroehlich 725126d
Remove execution permission
yvonnefroehlich 361e3aa
Remove unneeded docs
yvonnefroehlich 9c9d19f
Remove unneeded parameters from examples
yvonnefroehlich 9f1e812
Remove execution permission
yvonnefroehlich 789d82e
Improve names of parameters
yvonnefroehlich b38edf9
Remove execution permission
yvonnefroehlich c8c7f79
Update parameter list explanaition
yvonnefroehlich ff04635
Remove execusion permission
yvonnefroehlich 32c5341
Fix typo
yvonnefroehlich b079fd9
Fix rst syntax
yvonnefroehlich 90a2890
Use variables for colors
yvonnefroehlich 4c6013e
Introduce transpareny for wordmark
yvonnefroehlich f8ac7c0
Follow code style
yvonnefroehlich bdb6f14
Adjustments for tranparency for wordmark
yvonnefroehlich 7416979
Remove execution permission
yvonnefroehlich ebdf4f2
Adjust example
yvonnefroehlich 6d01ec1
Remove execution permission
yvonnefroehlich a60a88c
Add comment as reminder
yvonnefroehlich ec4583c
Remove execution permission
yvonnefroehlich 4891de2
Combine box and bg_transparent to box parameter of Figure.image
yvonnefroehlich e3da0ce
Simplify code
yvonnefroehlich 78872b4
Adjust outline
yvonnefroehlich 470ed44
Try to use GMT color setting for font
yvonnefroehlich e77dde2
Remove unneeded code
yvonnefroehlich 126a574
Remove execution permission
yvonnefroehlich 5de8969
Polish code
yvonnefroehlich 77c12f8
Follow code style
yvonnefroehlich 76e1dac
Remove execution permission
yvonnefroehlich 366970a
Use specific variable names
yvonnefroehlich 43d6d92
Remove execution permission
yvonnefroehlich e401fea
Do rotation directly not eps export
yvonnefroehlich cbe6035
Remove execution permission
yvonnefroehlich e060bc7
Make full transparent
yvonnefroehlich d46d5e0
Use dicts
yvonnefroehlich cd38f53
Remove execution permission
yvonnefroehlich e8dd40c
Suppress code style fails because of to many statements PLR0915
yvonnefroehlich 87dd5b7
Remove execution permission
yvonnefroehlich 5f492d7
Add size of logo | add GMT in example | Polish code
yvonnefroehlich b8150a5
Follow code style
yvonnefroehlich 8355de0
Plot yellow lines via loop over list
yvonnefroehlich 7d382b0
Remove execution permission
yvonnefroehlich ff512cc
Plot red lines for letter M via loop over list
yvonnefroehlich c072743
Adjust variable name
yvonnefroehlich 5962954
Use dict
yvonnefroehlich 5175a28
Reduce number of branches to be not > 12
yvonnefroehlich 3768a06
Remove execution permission
yvonnefroehlich 433f8e4
Improve comments
yvonnefroehlich 479f4a2
Remove execution permission
yvonnefroehlich 4f9ae6f
Do not rotate initial basemap -> no need of resize in savefig
yvonnefroehlich 08c7e56
Follow code style
yvonnefroehlich 8cb9079
Remove execution permission
yvonnefroehlich d2f479d
No temp eps file for wordmark
yvonnefroehlich f304d49
Adjust position and font size for wordmark based on orientation
yvonnefroehlich f7a84c5
Follow code style
yvonnefroehlich b18f816
Comment code
yvonnefroehlich 5ff52a8
Remove execution permission
yvonnefroehlich 9297ac5
Adjust position of wordmark
yvonnefroehlich 50e361b
Remove execution permission
yvonnefroehlich 09471e8
Create pygmtlogo.py in src and move code
yvonnefroehlich 0a35459
Update __init__.py
yvonnefroehlich b4259ad
Update figure.py
yvonnefroehlich 06fbfbd
Update gallery exampel
yvonnefroehlich c9c9d75
Add Docstrings
yvonnefroehlich efff204
Fix import in Gallery example
yvonnefroehlich 7779832
Update index
yvonnefroehlich 79500dd
Update gallery example
yvonnefroehlich 7f9d57e
Update imports
yvonnefroehlich 2132e5e
Add tests
yvonnefroehlich 438a100
Follow code style
yvonnefroehlich cb854e3
Update docs
yvonnefroehlich 3d40b6a
Remove exectuion permission
yvonnefroehlich d81c077
Remove exection permission
yvonnefroehlich 2696234
Remove execution permission
yvonnefroehlich c9262cc
Update docstrings
yvonnefroehlich 5999c51
Follow rules for variable names and use no space between consonants
yvonnefroehlich 4121569
Reduce galler example
yvonnefroehlich 16eb3dc
Expand tests
yvonnefroehlich 6d71dc3
Set box default to None
yvonnefroehlich e8c693e
Plot without setting up basemap
yvonnefroehlich dcc38e1
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1a2ca98
Add more parameters
yvonnefroehlich d716bd5
Exclude PLR0913
yvonnefroehlich 59dff81
Update tests
yvonnefroehlich d35c445
Use default position=Non
yvonnefroehlich 13306c8
Remove blank line
yvonnefroehlich 78ea05a
Move function create_logo out of function pygmtlogo
yvonnefroehlich 7910e05
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 6ec39e7
Adjust defaults
yvonnefroehlich 787530d
Update gallery example
yvonnefroehlich 7601e93
Fix typo
yvonnefroehlich ec13d17
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1f1bfd9
Adjust gallery example
yvonnefroehlich 1b51c05
Adjust docstring
yvonnefroehlich ebcf510
Fix typo
yvonnefroehlich 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 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 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,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 |
This file contains 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 |
---|---|---|
|
@@ -427,6 +427,7 @@ def _repr_html_(self) -> str: | |
plot, | ||
plot3d, | ||
psconvert, | ||
pygmtlogo, | ||
rose, | ||
set_panel, | ||
shift_origin, | ||
|
This file contains 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 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,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", | ||
): | ||
""" | ||
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 | ||
|
||
# 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 | ||
|
||
# ----------------------------------------------------------------------------- | ||
# 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( | ||
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") |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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 orFalse
for black/whitetheme
:"light"
or "dark"shape
:"circle"
or"hex"
wordmark
:True
/False
/"horizontal"
/"vertical"
[True means "horizontal"].