-
Notifications
You must be signed in to change notification settings - Fork 244
Code PyGMT logo in PyGMT #3849
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
Open
yvonnefroehlich
wants to merge
427
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.
Open
Code PyGMT logo in PyGMT #3849
Changes from all commits
Commits
Show all changes
427 commits
Select commit
Hold shift + click to select a range
e86f164
Improve region and projection arguments
yvonnefroehlich ed4a782
Adjust pen for arrow
yvonnefroehlich 7fcbc03
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich e0ede2e
First version of polygon for letter M
yvonnefroehlich b8d9e8c
Get ride of the xshift for letter M
yvonnefroehlich 17c3503
Fine tune x and y values
yvonnefroehlich 80a1487
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 08b3551
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich f396ac0
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich e432f79
Improve comment
yvonnefroehlich fae8282
Use match case for theme
yvonnefroehlich e015226
Use case match for shpae
yvonnefroehlich aee2574
Use full line length
yvonnefroehlich 57fe4a9
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 0eacfa9
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 2a1464a
Save seperation lines
yvonnefroehlich a2c3da8
Remove seperation lines
yvonnefroehlich 0042ed9
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich c46658d
Fix typo
yvonnefroehlich f7082c4
Use line length
yvonnefroehlich ba7f14d
Add perspective parameter for letter M
yvonnefroehlich 1e3bea4
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich faa61dd
Define radii
yvonnefroehlich b75dbad
Improve code for compass
yvonnefroehlich 5e345e5
Draw letter G via x/y coordinates
yvonnefroehlich 3ffbcdf
Add numpy import
yvonnefroehlich d49633a
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 76dec8b
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich ff77fe8
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 86ded86
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich b352346
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 97ce3d7
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 97ee7dc
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich a546342
Use basemap and allow adding frame and gridlines for debugging
yvonnefroehlich 4003b3c
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich ec5be4a
Use variables
yvonnefroehlich 0584284
Add vertical line back
yvonnefroehlich d66c7b6
Use variable
yvonnefroehlich 0949d19
Use variable (leeter G)
yvonnefroehlich bb3bf23
Use half of the pen thickness of compass lines for
yvonnefroehlich ee94768
Calculate the position of letter M (sligthly above letter G)
yvonnefroehlich 9072f0d
Add extra vertical compass line above letters "G" and "M"
yvonnefroehlich a98d25c
Remove not needed return value
yvonnefroehlich 9de8f2e
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich b9de084
Improve plotting the curved horizontal line and the arrow
yvonnefroehlich 4b8e3b6
Add background color
yvonnefroehlich 29910ac
Follow line length limit
yvonnefroehlich aa6d936
Add perspective parameter for curved horizontal line of letter T
yvonnefroehlich 7cab1bb
Introduce radius for outer limit of curved horizontal line for letter T
yvonnefroehlich 039bad4
Remove frame and circles for orientation
yvonnefroehlich 3e8ae21
Update parameter names in tests
yvonnefroehlich 12be397
Remove tab by white spaces
yvonnefroehlich 5453d16
Remove unneeded comment
yvonnefroehlich 19c0d18
Adjust length of vertical line of compass
yvonnefroehlich 87ba6cf
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich a272a09
Adjust compass line ending at upper right corner of letter M
yvonnefroehlich 4bd8130
Define pen thickness
yvonnefroehlich 193f725
Fix code of orientation circles
yvonnefroehlich 22ecb94
Improve some comments
yvonnefroehlich ef619bc
Plot only lower part of vertical compass line
yvonnefroehlich 255f7fe
Use a slightly smaller arrow head for letter T
yvonnefroehlich 94f09d7
Remove 'color' from variable names
yvonnefroehlich 7afd52e
Add just radius for arrow
yvonnefroehlich 354e9a2
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich f994c9a
Out-comment fig.show
yvonnefroehlich f4269bb
Adjust position of horizontal wordmark
yvonnefroehlich afe3be6
Adjust position of vertical wordmark
yvonnefroehlich 736e60f
Adjust position of wordmark
yvonnefroehlich 0d8b931
Fit hexagon into circles
yvonnefroehlich fd93480
Correct horizontal compass line to be on top of Earth out line
yvonnefroehlich 5e8bd7e
Reorder parameters in function definition
yvonnefroehlich c8be168
Reorder docstrings
yvonnefroehlich 2273713
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1400ab6
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich fdbca4a
Import typing
yvonnefroehlich 8a79a38
Un-commend fig.show
yvonnefroehlich 1b107dc
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 43f79af
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 26c6dce
Use line length
yvonnefroehlich 98bcad8
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich efba97a
Polish
yvonnefroehlich c430948
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich b7d75e5
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich e0b61c8
Update comment
yvonnefroehlich 64f6c9a
Do not invert wordmark text in gray20, always use gray20
yvonnefroehlich bb31966
Revert "Do not invert wordmark text in gray20, always use gray20"
yvonnefroehlich 8b1fd34
Reduce examples
yvonnefroehlich f88f30f
Uncomment fig.show
yvonnefroehlich b238479
Not help gridlines
yvonnefroehlich 93c8ff5
Adjust background color in example
yvonnefroehlich b37e24e
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 3d030d8
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1d031be
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1deb35c
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich f70d2db
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich abc89a6
Exclude PLR0915
yvonnefroehlich 27937b5
Add pygmt import
yvonnefroehlich 4ed27a7
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 5953cc6
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich aad7292
Adjust line length
yvonnefroehlich 194b15d
Use new pythonic code for no frame
yvonnefroehlich f6e9b01
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 9920f90
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 12005a7
Define private functions for letter coordinates
yvonnefroehlich da985c6
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich a585464
Make private function
yvonnefroehlich 01f7c69
Add comment
yvonnefroehlich 5da7271
Fix
yvonnefroehlich adfd925
Use easier to understand code for letter G
yvonnefroehlich 625a1ff
Use shorter way to set maximum length
yvonnefroehlich a44dc64
Use shorter way to set zero as start
yvonnefroehlich 0a006bb
Remove close=True
yvonnefroehlich 7333e59
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 31955c6
Use more compact definition of letter G
yvonnefroehlich da0a5ef
Make coordinate calculation for curved top line of letter T clearer
yvonnefroehlich cada956
Add name for private function for letter G
yvonnefroehlich 46f3cbf
Add name for private function for letter T
yvonnefroehlich 3e6c4ba
Add name for private function for letter M
yvonnefroehlich 9257aae
Combine comment lines
yvonnefroehlich e6c21bd
Make compass line consisten with the defined thicknesses
yvonnefroehlich e9f6594
Remove comment
yvonnefroehlich b9a262d
Add private function for compass lines
yvonnefroehlich f226cac
Fix indent
yvonnefroehlich 28e055b
Define private function for vertical red line
yvonnefroehlich 2f92899
Make variable names consistent
yvonnefroehlich 832d836
Make variable names consistent
yvonnefroehlich 346c655
Add and improve private function names
yvonnefroehlich a57bb5c
Remove unneeded comments
yvonnefroehlich 23b6386
Move docs to plot function
yvonnefroehlich e3d6e0c
Fix mixed return onf red line coordinates
yvonnefroehlich 1bb046b
Fix typo
yvonnefroehlich 24c8760
Improve coordinates of letter M
yvonnefroehlich 44ba985
Introduce a third pen thickness for letters
yvonnefroehlich 70f6784
Return dicts by private functions
yvonnefroehlich adc2d78
Introduce third pen thickness for letters
yvonnefroehlich e730197
Add blank lines to improved readability of the code
yvonnefroehlich 979050c
Change thick to thicker and middle to thick
yvonnefroehlich a7f326c
Define fourth pen thickness 'thinner' for letter M to define variable…
yvonnefroehlich 0175f7f
Remove old definition of letter M, improve definition of m_y1
yvonnefroehlich 8f9e32e
Make gaps consistent
yvonnefroehlich c60018e
Use pen thickness variable
yvonnefroehlich 8001dd2
Use for descripte variable names for pen thicknesses and introduce pe…
yvonnefroehlich af31fa2
Redefine coordinates for letter M
yvonnefroehlich 61ae0c8
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 9c2c36f
Use variable "thick_gt"
yvonnefroehlich 130d1c3
Simplify condition for mask for letter T
yvonnefroehlich 1a73708
Shorten variable names for coordinates of letter M
yvonnefroehlich 0789876
Make gap for arrow head consistent with the other gaps
yvonnefroehlich a00e695
Improve comment
yvonnefroehlich bafc7a0
Define compass lines as vectors
yvonnefroehlich 9b4bd13
Fix typo
yvonnefroehlich 6e7fc83
Fix typo
yvonnefroehlich f171ab4
Add note regarding radii
yvonnefroehlich d0c8fda
Fix line length, add more help lines
yvonnefroehlich 1766e9c
Define variable x3 for curved top line of letter T
yvonnefroehlich 7f563e1
Add one more helping line
yvonnefroehlich fe109d9
Use finer discretization for clean endings of top curved line of lett…
yvonnefroehlich 1e889d2
Calculate compass line thickness from the thickness of the souronding…
yvonnefroehlich 47b2ca3
Remove inner compass lines
yvonnefroehlich 7da6093
Fix typos
yvonnefroehlich 73dc51a
Adjust radii and use fractional representation
yvonnefroehlich 0413225
Adjust thickness of gap
yvonnefroehlich 393a3c4
Plot red vertical line as polygon
yvonnefroehlich 8067fba
Limit all compass lines to abs(r1)
yvonnefroehlich c78c89c
Remove unneeded variable
yvonnefroehlich 718c7a2
Reorder code, improve comments
yvonnefroehlich 20b5d74
Add comment to explain plotting order
yvonnefroehlich 537e750
Improve plotting order
yvonnefroehlich 0515240
Add debug parameter to add helping lines
yvonnefroehlich 89bd0af
TEST: Adjustments for hexagon shape
yvonnefroehlich 7f8f99b
Remove old code parts
yvonnefroehlich 97d1af1
Use max line length
yvonnefroehlich 8df1bba
Plot vertical help lines in one plot call
yvonnefroehlich a27a6b4
Sorten descripition of function create_logo
yvonnefroehlich ca0eb16
Remove unneeded comment due to remove of inner compass lines
yvonnefroehlich 7d96502
Remove seperator
yvonnefroehlich 8fa1dee
Set coordinates in plot call for shape
yvonnefroehlich b120249
Remove fig.show
yvonnefroehlich ce173ec
Make create_logo a private function
yvonnefroehlich 409ab84
Allow setting hight and width for adding logo to the plot
yvonnefroehlich 894a51c
Add inline example
yvonnefroehlich fea12d4
Add perspective for helping lines
yvonnefroehlich c93c4bf
Limit helping lines to fit into frame even after rotation
yvonnefroehlich a0a38a4
Shorten variable name to fit into one line
yvonnefroehlich ab997e0
Try if code fits in one line
yvonnefroehlich cd3bb62
Try if code fits in one line
yvonnefroehlich 6ad9690
Combine compass lines into one plot call
yvonnefroehlich 4a522c6
TEST: Adjustments for hexagon shape size of r0
yvonnefroehlich 5989fad
Calculate curved top line of letter T based on South at 270 deg
yvonnefroehlich 8f9f8d0
Use 'thick_shape" for drawing outline for black-white dark case
yvonnefroehlich 23b3e39
TEST: Adjustments for hexagon shape size of r0+0.35
yvonnefroehlich d60a057
Define letter T entierly via a polygon
yvonnefroehlich e1c8964
Fixes for hexagon shape
yvonnefroehlich 98768a9
Adjust function explanation for letter T
yvonnefroehlich a5ba62a
Combine comment for letters
yvonnefroehlich 6b85259
Plot background line and arrow together
yvonnefroehlich 23bed9a
Merge remote-tracking branch 'origin/code-pygmt-logo' into code-pygmt…
yvonnefroehlich fa628d5
Adjust gap for arrow
yvonnefroehlich 96c9ed2
Adjust size of arrow head
yvonnefroehlich 01e6a41
Merge remote-tracking branch 'origin/code-pygmt-logo' into code-pygmt…
yvonnefroehlich 2964869
Fix line length
yvonnefroehlich 7efd08d
Remove gallery example
yvonnefroehlich 160dcdf
Update and add tests
yvonnefroehlich 8bc5a82
Plot vertical line and arrow head as one polygon
yvonnefroehlich 99aa2f5
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 562ffa4
Fix typo
yvonnefroehlich bf3d637
Reduce tests
yvonnefroehlich fb23907
Update intro text
yvonnefroehlich 698ddd7
Remove fig.show()
yvonnefroehlich 04f2ca5
Remove the projection and region parameters
yvonnefroehlich 59e56cb
Adjust formating of comments
yvonnefroehlich 25b55ad
Simplify calculation of thickness
yvonnefroehlich 13ad3b6
Remove region and projection parameters
yvonnefroehlich 729aa00
No wordmark by default
yvonnefroehlich fac0aba
Import pygmt into private function
yvonnefroehlich ece8214
Move definition of perspective
yvonnefroehlich 8778443
Use wordmark="none" instead of wordmark=False
yvonnefroehlich 1c1406c
Use GMTTempoaryFile and pass a tempoary file
yvonnefroehlich 7486e66
Improve description of test
yvonnefroehlich 74ab006
Fix style
yvonnefroehlich a4e378f
Add import of GMTTempFile
yvonnefroehlich ee1951d
Move import below docstring
yvonnefroehlich 8ae5c89
Fix file name variable
yvonnefroehlich 3cb5212
Combine tests
yvonnefroehlich 0291e93
Add type hints
yvonnefroehlich afa0887
Shorten docstring for theme
yvonnefroehlich de187e2
Use list for docstring of wordmark
yvonnefroehlich ee85374
Shorten docstring for color
yvonnefroehlich 382e288
Remove deleting file
yvonnefroehlich 5b28739
Add perspective parameter
yvonnefroehlich 9fc6c78
Import GMTTempFile at the beginning
yvonnefroehlich f2d2922
Sorten comment for perspective parameter
yvonnefroehlich 6aafe47
Update inline example
yvonnefroehlich 6cdce1b
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 862c9cd
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 1c51189
Fix parameter name in test
yvonnefroehlich 124d21a
Add test_pygmtlogo.png into DVC
6878e26
Remove execution permission
yvonnefroehlich 194c3e0
Adjust workflow dvc-diff
yvonnefroehlich 0ed5cc9
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich c614cdb
Use int for hex_factor
yvonnefroehlich 3597bd5
Give radii in a fraction of 128
yvonnefroehlich 4bc9f68
Extend docstrings
yvonnefroehlich 4a9c09b
Fix docstrings taken from helpers
yvonnefroehlich 1cb524c
Improve comment for inline example
yvonnefroehlich 58123a7
Add docstring for position parameter
yvonnefroehlich 47699a8
Add docstrings for width, height, and box
yvonnefroehlich ec3b72d
Use full line length
yvonnefroehlich 816178a
Merge branch 'main' into code-pygmt-logo
yvonnefroehlich 31972c2
Add pygmtlogo to figure.py
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,360 @@ | ||
| """ | ||
| pygmtlogo - Plot the PyGMT logo. | ||
|
|
||
| The initial design of the logo is kindly provided by `@sfrooti <https://github.com/sfrooti>`_ | ||
| and consists of a visual and the wordmark "PyGMT". | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
| from typing import Literal | ||
|
|
||
| import numpy as np | ||
| from pygmt._typing import AnchorCode, PathLike | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| from pygmt.helpers import GMTTempFile, fmt_docstring | ||
| from pygmt.params import Box, Position | ||
|
|
||
| __doctest_skip__ = ["pygmtlogo"] | ||
|
|
||
|
|
||
| def _create_logo( # noqa: PLR0915 | ||
| shape: Literal["circle", "hexagon"] = "circle", | ||
| theme: Literal["light", "dark"] = "light", | ||
| wordmark: Literal["none", "horizontal", "vertical"] = "none", | ||
| color: bool = True, | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| figname: PathLike = "pygmt_logo.eps", | ||
| debug: bool = False, | ||
| ): | ||
| """ | ||
| Create the PyGMT logo using PyGMT. | ||
| """ | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| from pygmt.figure import Figure # noqa: PLC0415 | ||
|
|
||
| # Helpful definitions | ||
| size = 4 | ||
| region = [-size, size] * 2 | ||
| proj = "x1c" | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| # Rotation around z-axis by 30 degrees counter-clockwise placed in the center. | ||
| perspective = "30+w0/0" | ||
|
|
||
| # Radii (make sure that r4-r5 == r2-r3) | ||
| r0, r1, r2, r3, r4, r5 = size * np.array([128, 112, 75, 61, 53, 39]) / 128 | ||
| # Pen thicknesses | ||
| 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_shape / 4 | ||
|
|
||
| # Define colors | ||
| color_light = "white" | ||
| color_dark = "gray20" | ||
|
|
||
| blue = "48/105/152" # Python blue | ||
| yellow = "255/212/59" # Python yellow | ||
| red = "238/86/52" # GMT red | ||
| if not color: | ||
| blue = yellow = red = color_dark | ||
| if theme == "dark": | ||
| blue = yellow = red = color_light | ||
|
|
||
| # Background and wordmark | ||
| match theme: | ||
| case "light": | ||
| color_bg = color_light | ||
| color_py = blue | ||
| color_gmt = color_dark | ||
| case "dark": | ||
| color_bg = color_dark | ||
| color_py = yellow | ||
| color_gmt = color_light | ||
|
|
||
| # Define shape | ||
| match shape: | ||
| case "circle": | ||
| symbol = "c" | ||
| size_shape = r0 + r1 | ||
| hex_factor = 1.0 | ||
| case "hexagon": | ||
| symbol = "h" | ||
| size_shape = (r0 + 0.34) * 2 | ||
| hex_factor = 1.1 | ||
|
|
||
| # Define wordmark | ||
| font = "AvantGarde-Book" | ||
| match wordmark: | ||
| case "vertical": | ||
| args_text_wm = {"x": 0, "y": -4.5, "justify": "CT", "font": f"2.5c,{font}"} | ||
| case "horizontal": | ||
| args_text_wm = {"x": 4.5, "y": 0.8, "justify": "LM", "font": f"8c,{font}"} | ||
|
|
||
| def _letter_g_coords(): | ||
| """Coordinates for letter G.""" | ||
| outer_angles = np.deg2rad(np.arange(90, 361)) | ||
| inner_angles = outer_angles[::-1] | ||
| offset = thick_gt / 2 | ||
| # Outer arc (r4) | ||
| arc_outer_x, arc_outer_y = np.cos(outer_angles) * r4, np.sin(outer_angles) * r4 | ||
| # Connecting lines | ||
| connector_x, connector_y = [r4, 0, 0, r5], [offset, offset, -offset, -offset] | ||
| # Inner arc (r5) | ||
| arc_inner_x, arc_inner_y = np.cos(inner_angles) * r5, np.sin(inner_angles) * r5 | ||
| # Combine all coordinates (outer arc, connectors, inner arc) | ||
| g_x = np.concatenate([arc_outer_x, connector_x, arc_inner_x]) | ||
| g_y = np.concatenate([arc_outer_y, connector_y, arc_inner_y]) | ||
| return {"x": g_x, "y": g_y} | ||
|
|
||
| def _letter_m_coords(): | ||
| """Coordinates for letter M.""" | ||
| # X-coordinates from left to right. | ||
| x1 = thick_gap # Left edge of left vertical line of M. | ||
| x5 = r4 # Right edge of right vertical line of M. | ||
| x2 = x1 + thick_m # Right edge of left vertical line of M. | ||
| x3 = (x1 + x5) / 2 # The middle of M. | ||
| x4 = x5 - thick_m # Left edge of right vertical line of M. | ||
| # Y-coordinates from bottom to top. | ||
| y1 = thick_gt / 2 + thick_gap # Bottom of the letter M. | ||
| y2 = r5 - thick_gt # Bottom of the middle peak of M. | ||
| y3 = r5 # Top of the middle peak of M. | ||
| y4 = r4 # Top of letter M. | ||
| # X- and Y-coordinates of the letter M, starting from the left edge of the left | ||
| # vertical line and going clockwise. | ||
| m_x = [x1, x1, x2, x3, x4, x5, x5, x4, x4, x3, x2, x2] | ||
| m_y = [y1, y4, y4, y3, y4, y4, y1, y1, y3, y2, y3, y1] | ||
| return {"x": m_x, "y": m_y} | ||
|
|
||
| def _letter_t_coords(): | ||
| """Coordinates for letter T.""" | ||
| outer_angles = np.deg2rad(np.arange(240, 300, 0.5)) | ||
| inner_angles = outer_angles[::-1] | ||
| arc_outer_x, arc_outer_y = np.cos(outer_angles) * r2, np.sin(outer_angles) * r2 | ||
| arc_inner_x, arc_inner_y = np.cos(inner_angles) * r3, np.sin(inner_angles) * r3 | ||
| # The arrowhead is an equilateral triangle | ||
| x0 = thick_gt / 2 # Extra half-width for arrow head | ||
| y0 = 1.8 * x0 * np.sqrt(3) # Height for arrow head | ||
| arrow_x = [-x0, -x0, -x0 * 2.0, 0, x0 * 2.0, x0, x0] | ||
| arrow_y = [-r2, -r0 + y0, -r0 + y0, -r0, -r0 + y0, -r0 + y0, -r2] | ||
| mask_left = arc_outer_x < -x0 | ||
| mask_right = arc_outer_x > x0 | ||
| t_x = np.concatenate( | ||
| [arc_inner_x, arc_outer_x[mask_left], arrow_x, arc_outer_x[mask_right]] | ||
| ) | ||
| t_y = np.concatenate( | ||
| [arc_inner_y, arc_outer_y[mask_left], arrow_y, arc_outer_y[mask_right]] | ||
| ) | ||
| # Ensure the same X-coordinate for the right edge of T and the middle of M. | ||
| mask = np.abs(t_x) <= (thick_gap + r4) / 2 | ||
| return {"x": t_x[mask], "y": t_y[mask]} | ||
|
|
||
| def _bg_arrow_coords(): | ||
| """Coordinates for the background arrow.""" | ||
| # x0, y0 is the same as in _letter_t_coords(). | ||
| x0 = thick_gt / 2 | ||
| y0 = 1.8 * x0 * np.sqrt(3) | ||
| # The background arrow is thick_comp wider than the letter T. | ||
| x1 = x0 + thick_comp / 2.0 # Half-width of the arrow tail | ||
| x2 = 2 * x0 + thick_comp / np.sqrt(3) # Half-width of the arrow head | ||
|
|
||
| arrow_x = [-x1, -x1, -x2, -(x2 - 2 * x0), (x2 - 2 * x0), x2, x1, x1] | ||
| arrow_y = [r0, -r0 + y0, -r0 + y0, -r0, -r0, -r0 + y0, -r0 + y0, r0] | ||
| return {"x": arrow_x, "y": arrow_y} | ||
|
|
||
| def _compass_lines(): | ||
| """Coordinates of compass lines.""" | ||
| sqrt2 = np.sqrt(2) / 2 | ||
| x1, x2, x3 = r0 * sqrt2, r3 * sqrt2, (r2 + (r3 - r4)) * sqrt2 | ||
| # Coordinates of vectors in the format of (x_start, y_start, x_end, y_end). | ||
| return [ | ||
| (-r0 * hex_factor, 0, -r3, 0), # left horizontal | ||
| (r3, 0, r0 * hex_factor, 0), # right horizontal | ||
| (-x1, x1, -x2, x2), # upper left | ||
| (-x1, -x1, -x2, -x2), # lower left | ||
| (x1, x1, x3, x3), # upper right | ||
| (x1, -x1, x2, -x2), # lower right | ||
| ] | ||
|
|
||
| def _vline_coords(): | ||
| """ | ||
| Coordinates for the vertical line at the top. | ||
| """ | ||
| x0 = thick_gt / 2 | ||
| return {"x": [-x0, -x0, x0, x0], "y": [r0, r3, r3, r0]} | ||
|
|
||
| fig = Figure() | ||
| fig.basemap(region=region, projection=proj, perspective=perspective, frame="none") | ||
|
|
||
| # Earth - circle / hexagon | ||
| args_shape = { | ||
| "style": f"{symbol}{size_shape}c", | ||
| "perspective": True, | ||
| "no_clip": True, # Needed for corners of hexagon shape | ||
| } | ||
| # Shape fill | ||
| fig.plot(x=0, y=0, fill=color_bg, **args_shape) | ||
|
|
||
| # Compass lines | ||
| fig.plot( | ||
| data=_compass_lines(), | ||
| pen=f"{thick_comp}c,{yellow}", | ||
| style="v0c+s", | ||
| perspective=True, | ||
| no_clip=True, | ||
| ) | ||
|
|
||
| # Shape outline (over ends of compass lines for hexagon shape) | ||
| fig.plot(x=0, y=0, pen=f"{thick_shape}c,{blue}", **args_shape) | ||
|
|
||
| # Arrow in background color (over shape outline but under letters) | ||
| fig.plot(data=_bg_arrow_coords(), fill=color_bg, perspective=True) | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
|
|
||
| # Letters G, M, and T | ||
| fig.plot(data=_letter_g_coords(), fill=red, perspective=True) | ||
| fig.plot(data=_letter_m_coords(), fill=red, perspective=True) | ||
| fig.plot(data=_letter_t_coords(), fill=red, perspective=True) | ||
|
|
||
| # Upper vertical line | ||
| fig.plot(data=_vline_coords(), fill=red, perspective=True) | ||
|
|
||
| # Outline around the shape for black and white color with dark theme | ||
| if not color and theme == "dark": | ||
| fig.plot( | ||
| x=0, | ||
| y=0, | ||
| style=f"{symbol}{size_shape + thick_shape}c", | ||
| pen=f"1p,{color_dark}", | ||
| perspective=True, | ||
| no_clip=True, | ||
| ) | ||
|
|
||
| # Add wordmark "PyGMT" | ||
| if wordmark != "none": | ||
| text_wm = f"@;{color_py};Py@;;@;{color_gmt};GMT@;;" | ||
| fig.text(text=text_wm, no_clip=True, **args_text_wm) | ||
|
|
||
| # Helpful for implementing the logo; not included in the logo | ||
| if debug: | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| from pygmt import config # noqa: PLC0415 | ||
|
|
||
| # Gridlines | ||
| with config(MAP_FRAME_TYPE="inside", MAP_GRID_PEN="0.1p,gray30"): | ||
| fig.basemap(frame="g1") | ||
| # Circles for the different radii | ||
| for r in [r0, r1, r2, r3, r4, r5]: | ||
| fig.plot(x=0, y=0, style=f"c{2 * r}c", pen="0.3p,gray30") | ||
| pen = "0.3p,gray30,2_2" | ||
| fig.plot(x=0, y=0, style=f"c{2 * (r2 + (r3 - r4))}c", pen=pen) | ||
| # Lines for letter M | ||
| fig.hlines(y=[r4, r5], xmin=-3, pen=pen, perspective=True) | ||
| fig.vlines(x=[r4, (thick_gap + r4) / 2], ymax=3, pen=pen, perspective=True) | ||
|
|
||
| fig.savefig(fname=figname) | ||
|
|
||
|
|
||
| @fmt_docstring | ||
| def pygmtlogo( # noqa: PLR0913 | ||
| self, | ||
| shape: Literal["circle", "hexagon"] = "circle", | ||
| theme: Literal["light", "dark"] = "light", | ||
| wordmark: Literal["none", "horizontal", "vertical"] = "none", | ||
| color: bool = True, | ||
| width: float | str | None = None, | ||
| height: float | str | None = None, | ||
| position: Position | Sequence[float | str] | AnchorCode | None = None, | ||
| box: Box | bool = False, | ||
| verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | ||
| | bool = False, | ||
| panel: int | Sequence[int] | bool = False, | ||
| perspective: float | Sequence[float] | str | bool = False, | ||
| transparency: float | None = None, | ||
| ): | ||
| r""" | ||
| Plot the PyGMT logo. | ||
| The design of the logo is kindly provided by `@sfrooti <https://github.com/sfrooti>`_ | ||
| and consists of a visual and the wordmark "PyGMT". | ||
|
|
||
| Parameters | ||
| ---------- | ||
| shape | ||
| Shape of the visual logo. Use ``"circle"`` for a circle shape [Default] or | ||
| ``"hexagon"`` for a hexagon shape. | ||
| theme | ||
| Use ``"light"`` for light mode (i.e., a white background) [Default] and | ||
| ``"dark"`` for dark mode (i.e., a darkgray background). | ||
| wordmark | ||
| Add the wordmark "PyGMT" and adjust its orientation relative to the visual. | ||
| Valid values are: | ||
|
|
||
| - ``"none"``: no wordmark [Default]. | ||
| - ``"horizontal"``: wordmark at the right side of the visual. | ||
| - ``"vertical"``: wordmark below the visual. | ||
| color | ||
| ``True`` for a color logo, and ``False`` for a black and white logo. | ||
| position | ||
| 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 Bottom Left corner of the plot (position | ||
| ``(0, 0)`` with anchor ``"BL"``). | ||
| width | ||
| height | ||
| Width or height of the PyGMT logo. Since the aspect ratio is fixed, only one of | ||
| the two can be specified. | ||
| 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, | ||
| pass a :class:`pygmt.params.Box` object to control style, fill, pen, and other | ||
| box properties. | ||
| $verbose | ||
| $panel | ||
| $perspective | ||
| $transparency | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import pygmt | ||
|
|
||
| The simplest way to plot the PyGMT logo is to call the method without any arguments. | ||
|
|
||
| >>> fig = pygmt.Figure() | ||
| >>> fig.pygmtlogo() | ||
| >>> fig.show() | ||
|
|
||
| Plot the PyGMT logo with the wordmark "PyGMT" with a height of 1 centimeter at the | ||
| right side in the Bottom Right corner on an existing basemap: | ||
|
|
||
| >>> fig = pygmt.Figure() | ||
| >>> fig.basemap(region=[-90, -70, 0, 20], projection="M10c", frame=True) | ||
| >>> fig.pygmtlogo( | ||
| ... wordmark="horizontal", | ||
| ... position="BR", | ||
| ... height="1c", | ||
| ... ) | ||
|
seisman marked this conversation as resolved.
|
||
| >>> fig.show() | ||
| """ | ||
| with GMTTempFile(suffix=".eps") as logofile: | ||
| # Create logo file | ||
| _create_logo( | ||
| color=color, | ||
| theme=theme, | ||
| shape=shape, | ||
| wordmark=wordmark, | ||
| figname=logofile.name, | ||
| ) | ||
|
|
||
| # Add to existing Figure instance | ||
| self.image( | ||
| imagefile=logofile.name, | ||
| position=position, | ||
| width=width, | ||
| height=height, | ||
| box=box, | ||
| verbose=verbose, | ||
| panel=panel, | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| perspective=perspective, | ||
| transparency=transparency, | ||
| ) | ||
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,6 @@ | ||
| outs: | ||
| - md5: 35c59c31c92f13c705a24933465ff551 | ||
| size: 14374 | ||
| isexec: true | ||
|
Member
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. This line says that the |
||
| hash: md5 | ||
| path: test_pygmtlogo.png | ||
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.
Uh oh!
There was an error while loading. Please reload this page.