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

Figure.image: Add alias "bitcolor" for "G" #2615

Merged
merged 11 commits into from
Jul 29, 2023
13 changes: 11 additions & 2 deletions pygmt/src/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

@fmt_docstring
@use_alias(
R="region",
J="projection",
D="position",
F="box",
G="bitcolor",
J="projection",
M="monochrome",
R="region",
V="verbose",
c="panel",
p="perspective",
Expand Down Expand Up @@ -49,6 +50,14 @@ def image(self, imagefile, **kwargs):
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
If set to ``True``, draw a rectangular border around the image
using :gmt-term:`MAP_FRAME_PEN`.
bitcolor : str or list
Copy link
Member

Choose a reason for hiding this comment

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

Is a list allowed?

Copy link
Member Author

Choose a reason for hiding this comment

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

A list can be used to set both foreground and background colors of 1-bit images:

import pygmt

fig = pygmt.Figure()

for i_G in [
        None,
        "blue+b",
        ["blue+b", "red+f"],
]:
    fig.image(imagefile="@vader1.png", G=i_G)  
    fig.shift_origin(xshift="1c")

fig.show()
# fig.savefig(fname="image_Q_list.png")

Output figure:
image_Q_list

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, thanks for the example! So the list would translate to -Gblue+b -Gred+f. Makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly! Maybe moving the sentence "Can be repeated with different settings." upwards makes this a bit clearer (please see commit 951a110)?

[*color*][**+b**\|\ **f**\|\ **t**].
Change certain pixel values to another color or make them transparent.
For 1-bit images you can specify an alternate *color* for the
background (**+b**) or the foreground (**+f**) pixels, or give no color
to make those pixels transparent. Can be repeated with different
settings. Alternatively, for color images you can select a single
*color* that should be made transparent instead (**+t**).
monochrome : bool
Convert color image to monochrome grayshades using the (television)
YIQ-transformation.
Expand Down