Skip to content

Allow passing an array as intensity for plot #1065

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

Merged
merged 23 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
)
extra_arrays.append(sizes)

if "I" in kwargs and is_nonstr_iter(kwargs["I"]):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for intensity if data is matrix or file."
)
extra_arrays.append(kwargs["I"])
kwargs["I"] = ""

if "t" in kwargs and is_nonstr_iter(kwargs["t"]):
extra_arrays.append(kwargs["t"])
kwargs["t"] = ""
Expand Down
49 changes: 48 additions & 1 deletion pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def test_plot_fail_no_data(data):

def test_plot_fail_size_color(data):
"""
Should raise an exception if array sizes and color are used with matrix.
Should raise an exception if array color, sizes and intensity are used with
matrix.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
Expand All @@ -117,6 +118,16 @@ def test_plot_fail_size_color(data):
color="red",
frame="afg",
)
with pytest.raises(GMTInvalidInput):
fig.plot(
data=data,
region=region,
projection="X4i",
style="c0.2c",
color="red",
frame="afg",
intensity=data[:, 2],
)


@check_figures_equal()
Expand Down Expand Up @@ -231,6 +242,42 @@ def test_plot_colors_sizes_proj(data, region):
return fig


@check_figures_equal()
def test_plot_varying_intensity():
"""
Plot the data with array-like intensity.
"""
x = np.arange(1, 10)
y = np.arange(1, 10)
intensity = np.linspace(-1, 1, len(x))

fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
with GMTTempFile() as tmpfile:
np.savetxt(tmpfile.name, np.c_[x, y, intensity], fmt="%s")
fig_ref.plot(
data=tmpfile.name,
R="0/10/0/10",
J="X4i",
B="",
S="c0.2c",
G="blue",
I="",
)

fig_test.plot(
x=x,
y=y,
region=[0, 10, 0, 10],
projection="X4i",
frame=True,
style="c0.2c",
color="blue",
intensity=intensity,
)
return fig_ref, fig_test


@check_figures_equal()
def test_plot_transparency():
"""
Expand Down