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

Allow non-string color when input data is a matrix or a file for plot and plot3d #1526

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def plot(self, data=None, x=None, y=None, size=None, direction=None, **kwargs):
kwargs["S"] = "s0.2c"
except FileNotFoundError:
pass
if "G" in kwargs and not isinstance(kwargs["G"], str):
if "G" in kwargs and is_nonstr_iter(kwargs["G"]):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for color if data is matrix or file."
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def plot3d(
kwargs["S"] = "u0.2c"
except FileNotFoundError:
pass
if "G" in kwargs and not isinstance(kwargs["G"], str):
if "G" in kwargs and is_nonstr_iter(kwargs["G"]):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for color if data is matrix or file."
Expand Down
7 changes: 4 additions & 3 deletions pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,13 @@ def test_plot_sizes_colors_transparencies():
return fig


@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(filename="test_plot_matrix.png")
@pytest.mark.parametrize("color", ["#aaaaaa", 170])
Copy link
Member

@weiji14 weiji14 Oct 5, 2021

Choose a reason for hiding this comment

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

Should we set G="sequence" so that people can input RGB or CMYK colors as a list like [170, 170, 170] or [0, 0, 0, 33] which gets converted to 170/170/170 and 0/0/0/33 respectively? Ref https://docs.generic-mapping-tools.org/6.2/gmtcolors.html#description.

Edit: Oh wait, this will be messy since color can be a 1d array... Maybe not.

@pytest.mark.xfail(
condition=gmt_version <= Version("6.2.0"),
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/5799.",
)
def test_plot_matrix(data):
def test_plot_matrix(data, color):
"""
Plot the data passing in a matrix and specifying columns.
"""
Expand All @@ -317,7 +318,7 @@ def test_plot_matrix(data):
region=[10, 70, -5, 10],
projection="M15c",
style="cc",
color="#aaaaaa",
color=color,
frame="a",
incols="0,1,2+s0.5",
)
Expand Down
6 changes: 4 additions & 2 deletions pygmt/tests/test_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def test_plot3d_sizes_colors_transparencies():


@pytest.mark.mpl_image_compare
def test_plot3d_matrix(data, region):
@pytest.mark.mpl_image_compare(filename="test_plot3d_matrix.png")
@pytest.mark.parametrize("color", ["#aaaaaa", 170])
def test_plot3d_matrix(data, region, color):
"""
Plot the data passing in a matrix and specifying incols.
"""
Expand All @@ -325,7 +327,7 @@ def test_plot3d_matrix(data, region):
region=region,
projection="M20c",
style="c1c",
color="#aaaaaa",
color=color,
frame=["a", "za"],
incols="0,1,2",
)
Expand Down