-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add a gallery example showing how to use patterns via the "fill" parameter (or similar parameters) #2329
Merged
Merged
Add a gallery example showing how to use patterns via the "fill" parameter (or similar parameters) #2329
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
54abdee
Add code for gallery example 'patterns.py'
yvonnefroehlich d88691a
Fix typos in comments
yvonnefroehlich e0ad0ad
Set 644 permission
yvonnefroehlich 08c8ce3
Use UNIX line breaks
yvonnefroehlich 1082c13
Show various patterns
yvonnefroehlich bd46172
Remove general pattern comment above loop
yvonnefroehlich 867de72
Adjust size of figure
yvonnefroehlich 5e4f4e1
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich e9de513
Fix typo in comment
yvonnefroehlich 50e3eb4
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 01b7358
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich cc7119f
Add link to the pattern overview in the GMT documentation
yvonnefroehlich 1a061da
Add documentation
yvonnefroehlich 6a75bb4
Fix line length
yvonnefroehlich eb31926
Add documentation
yvonnefroehlich c85043a
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 25c3777
Update 'E and 'G' of 'coast' to 'extensionfill' and 'compressionfill'
yvonnefroehlich a5fd42f
Add 'pygmt.Figure.velo' to list
yvonnefroehlich c2c0015
Add 'pygmt.Figure.solar' to list
yvonnefroehlich fd0386d
Sort items in list alphabetically
yvonnefroehlich 92caaf3
Improve formulation
yvonnefroehlich 567b555
Sort items in list alphabetically
yvonnefroehlich b011799
Restructure list
yvonnefroehlich 7ef4aae
Sort items in list alphabetically
yvonnefroehlich b8187d1
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 1b04163
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich ea07668
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 33477bb
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich f147e2a
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 4bb71b9
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 77816a9
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 7f6d413
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich fc58d96
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 73c79e7
Add basic docs
yvonnefroehlich e560c58
Fix typo
yvonnefroehlich d6452ba
Improve formulation (code review)
yvonnefroehlich c34b850
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 18cf6be
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich 8ffbb74
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich bc6c7ba
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich ba22af4
Fix general syntax for pattern (code review)
yvonnefroehlich 4434c07
Move interation to end of loop (code review)
yvonnefroehlich 7b8cffb
Merge branch 'main' into add-gallery-pattern
yvonnefroehlich e2b520e
Split syntax for pattern in two lines to fit line length
yvonnefroehlich 0518f67
Shorten syntax for pattern to fit line length (code review)
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
r""" | ||
Bit and Hachure Patterns | ||
------------------------ | ||
|
||
PyGMT allows using bit or hachure patterns via the ``fill`` parameter | ||
or similar parameters: | ||
|
||
- :meth:`pygmt.Figure.coast`: Land and water masses via ``land`` and | ||
``water``, respectively | ||
- :meth:`pygmt.Figure.histogram`: Histogram bars via ``fill`` | ||
- :meth:`pygmt.Figure.meca`: Focal mechanisms via ``compressionfill`` | ||
and ``extensionfill`` | ||
- :meth:`pygmt.Figure.plot`: Symbols and polygons via ``fill`` | ||
- :meth:`pygmt.Figure.rose`: Histogram sectors via ``fill`` | ||
- :meth:`pygmt.Figure.solar`: Day-light terminators via ``fill`` | ||
- :meth:`pygmt.Figure.ternary`: Symbols via ``fill`` | ||
- :meth:`pygmt.Figure.velo`: Uncertainty wedges and velocity error | ||
ellipses via ``uncertaintyfill`` | ||
- :meth:`pygmt.Figure.wiggle`: Anomalies via ``fillpositive`` | ||
and ``fillnegative`` | ||
|
||
The required argument has the following form: | ||
|
||
**P**\ |**p**\ *pattern*\ [**+b**\ *color*\ ][**+f**\ *color*\ ][**+r**\ *dpi*] | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
*pattern* can either be a number in the range 1–90 or the name of a | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1-, 8-, or 24-bit image raster file. The former will result in one of the 90 | ||
predefined 64 x 64 bit-patterns provided with GMT; an overview can by found at | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
https://docs.generic-mapping-tools.org/latest/cookbook/predefined-patterns.html. | ||
The latter allows the user to create customized, repeating images using image | ||
raster files. | ||
By specifying upper case **P** instead of **p** the image will be | ||
bit-reversed, i.e., white and black areas will be interchanged (only applies | ||
to 1-bit images or predefined bit-image patterns). | ||
For these patterns and other 1-bit images one may specify alternative | ||
**b**\ ackground and **f**\ oreground colors (by appending **+b**\ *color* | ||
and/or **+f**\ *color*) that will replace the default white and black pixels, | ||
respectively. Excluding *color* from a fore- or background specification yields | ||
a transparent image where only the back- or foreground pixels will be painted. | ||
The **+r**\ *dpi* modifier sets the resolution in dpi. | ||
""" | ||
|
||
import pygmt | ||
|
||
y = 13 | ||
|
||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig = pygmt.Figure() | ||
fig.basemap( | ||
region=[0, 10, 0, 12], | ||
projection="X10c", | ||
frame="rlbt+glightgray+tBit and Hachure Patterns", | ||
) | ||
|
||
# To use a pattern as fill append "p" and the number of the desired | ||
# pattern. By default, the pattern is plotted in black and white | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# with a resolution of 300 dpi | ||
for pattern in [ | ||
# Plot a hachted pattern via pattern number 8 | ||
"p8", | ||
# Plot a dotted pattern via pattern number 19 | ||
"p19", | ||
# Set the background color ("+b") to "red3" | ||
# and the foreground color ("+f") to "lightgray" | ||
"p19+bred3+flightbrown", | ||
# Invert the pattern by using a capitalized "P" | ||
"P19+bred3+flightbrown", | ||
# Change the resolution ("+r") to 100 dpi | ||
"p19+bred3+flightbrown+r100", | ||
# Make the background transparent by not giving a color after "+b"; | ||
# works analogous for the foreground | ||
"p19+b+flightbrown+r100", | ||
]: | ||
y -= 2 | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Plot a square with the pattern as fill | ||
fig.plot( | ||
x=2, | ||
y=y, | ||
style="s2c", # square with a width of 2 centimeters | ||
pen="1p,black", # 1 point thick, black outline | ||
fill=pattern, | ||
) | ||
# Add a description of the pattern | ||
fig.text( | ||
x=4, | ||
y=y, | ||
text=pattern, | ||
font="Courier-Bold", | ||
justify="ML", # justification of the text is Middle Left | ||
) | ||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.show() |
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.
I wonder if we should define a class for GMT patterns, e.g.,
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.
Additional to the list at the beginning of this example, there is also the possibility to add a pattern via the
dcw
andframe
parameters. The syntax seems to be difficult, as it seems to be something like +g p|P resolution / pattern. The functionality seems to be limited, as it seems that no foreground and background colors could be given (please correct me if I am wrong, so far I did not figure out how to set colors here).Example code
Output figure
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.
This is the old syntax of patterns for GMT 4. The full old syntax is -Gpdpi/pattern[:Bcolor[Fcolor]]. I think the old syntax is still supported in GMT5 and GMT6 (backward compatibility), but it's no longer documented.
As I understand it, it's impossible to specify foreground/background colors and dpi using the new syntax in
coast -E
.Ping @PaulWessel for comments on this.
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.
Maybe we should we open a separate issue for this?
Edit 2023/03/17: Please see issue #2438.