Skip to content

Commit

Permalink
Allow non-string color when input data is a matrix or a file for plot…
Browse files Browse the repository at this point in the history
… and plot3d (#1526)

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

* Expand existing tests to test int type colors
  • Loading branch information
seisman authored Oct 7, 2021
1 parent d4d3a4d commit 0d07ccc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
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])
@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

0 comments on commit 0d07ccc

Please sign in to comment.