-
Notifications
You must be signed in to change notification settings - Fork 229
Add a Pen class for specifying pen attributes #1239
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
base: main
Are you sure you want to change the base?
Conversation
Start a `pygmt.param.Pen` convenience class that generates a string which can be passed into GMT's pen (-W) parameter. The Pen class is structured to be under a 'param' folder. Added three basic unit tests to ensure various width/color/style combinations will be output correctly.
Placing the API docs for param.Pen under a new 'Parameters' subsection. 'Specifying pen attributes' documentation is copied from GMT cookbook, with examples modified to use the PyGMT syntax.
/format |
Reviving this after almost four and a half years! Have refactored things slightly to build on top of #3995. Now deciding how to handle slightly various pen/-W implementations across different GMT modules:
plus some others too, but too lazy to list them. Thoughts? |
I feel that a pen like As for the module-specific prefix/suffix/modifiers, I think we should leave them to the wrapper instead. For example,
|
color : str | ||
The *color* can be specified in five different ways: | ||
|
||
- Gray. Specify a *gray* shade in the range 0-255 (linearly going | ||
from black [0] to white [255]). | ||
|
||
- RGB. Specify *r*/*g*/*b*, each ranging from 0-255. Here 0/0/0 is | ||
black, 255/255/255 is white, 255/0/0 is red, etc. Alternatively, | ||
you can give RGB in hexadecimal using the *#rrggbb* format. | ||
|
||
- HSV. Specify *hue*-*saturation*-*value*, with the former in the | ||
0-360 degree range while the latter two take on the range 0-1 [17]_. | ||
|
||
- CMYK. Specify *cyan*/*magenta*/*yellow*/*black*, each ranging | ||
from 0-100%. | ||
|
||
- Name. Specify one of 663 valid color names. See | ||
:gmt-docs:`gmtcolors` for a list of all valid names. A very small | ||
yet versatile subset consists of the 29 choices *white*, *black*, and | ||
[light\|\ dark]{*red, orange, yellow, green, cyan, blue, magenta, | ||
gray\|\ grey, brown*\ }. The color names are case-insensitive, so | ||
mixed upper and lower case can be used (like *DarkGreen*). |
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.
The description for color
can also be applied to parameters like fill
. I guess we can move these paragraphs to a separate page under "Technical Reference" section.
""" | ||
assert str(Pen(width=1)) == "1,," | ||
assert str(Pen(color="yellow")) == ",yellow," | ||
assert str(Pen(style="-.-")) == ",,-.-" |
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.
Do we want ,,-.-
or just -.-
?
Description of proposed changes
Start a
pygmt.params.Pen
convenience class that generates a string which can be passed into GMT's pen (-W) parameter. The Pen class is structured to be under a 'params' folder. Added three basic unit tests to ensure various width/color/style combinationswill be output correctly. Note that this is still a basic implementation, and does not include advanced
+
modifiers as in https://docs.generic-mapping-tools.org/6.5/plot.html#w.Preview API docs at https://pygmt-dev--1239.org.readthedocs.build/en/1239/api/generated/pygmt.params.Pen.html
Example code:
produces:
References:
Fixes #1173, part of #1082
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version