Skip to content

Commit

Permalink
Let plot3d accept record by record transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Oct 26, 2020
1 parent bd07900 commit cdcd259
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,10 @@ def plot3d(
)
extra_arrays.append(sizes)

if "t" in kwargs and is_nonstr_iter(kwargs["t"]):
extra_arrays.append(kwargs["t"])
kwargs["t"] = ""

with Session() as lib:
# Choose how data will be passed in to the module
if kind == "file":
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_plot_varying_transparency():

@check_figures_equal()
def test_plot_sizes_colors_transparencies():
"Plot the data using z as transparency"
"Plot the data with varying sizes and colors using z as transparency"
x = np.arange(1.0, 10.0)
y = np.arange(1.0, 10.0)
color = np.arange(1, 10) * 0.15
Expand Down
125 changes: 121 additions & 4 deletions pygmt/tests/test_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,126 @@ def test_plot3d_colors_sizes_proj(data, region):
return fig_ref, fig_test


@check_figures_equal()
def test_plot3d_transparency():
"Plot the data with a constant transparency"
x = np.arange(1, 10)
y = np.arange(1, 10)
z = np.arange(1, 10) * 10

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, z], fmt="%d")
fig_ref.plot3d(
data=tmpfile.name,
S="u0.2c",
G="blue",
R="0/10/0/10/10/90",
J="X4i",
Jz=0.1,
B="",
p="135/30",
t=80.0,
)

fig_test.plot3d(
x=x,
y=y,
z=z,
style="u0.2c",
color="blue",
region=[0, 10, 0, 10, 10, 90],
projection="X4i",
zscale=0.1,
frame=True,
perspective=[135, 30],
transparency=80.0,
)
return fig_ref, fig_test


@check_figures_equal()
def test_plot3d_varying_transparency():
"Plot the data using z as transparency using 3-D column symbols"
x = np.arange(1, 10)
y = np.arange(1, 10)
z = np.arange(1, 10) * 10

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, z, z, z], fmt="%d")
fig_ref.plot3d(
data=tmpfile.name,
S="o0.2c+B5",
G="blue",
R="0/10/0/10/10/90",
J="X4i",
Jz=0.1,
B="",
p="135/30",
t="",
)
fig_test.plot3d(
x=x,
y=y,
z=z,
style="o0.2c+B5",
color="blue",
region=[0, 10, 0, 10, 10, 90],
projection="X4i",
zscale=0.1,
frame=True,
perspective=[135, 30],
transparency=z,
)
return fig_ref, fig_test


@check_figures_equal()
def test_plot3d_sizes_colors_transparencies():
"Plot the data with varying sizes and colors using z as transparency"
x = np.arange(1.0, 10.0)
y = np.arange(1.0, 10.0)
z = np.arange(1, 10) * 10
color = np.arange(1, 10) * 0.15
size = np.arange(1, 10) * 0.2
transparency = np.arange(1, 10) * 10

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, z, color, size, transparency])
fig_ref.plot3d(
data=tmpfile.name,
R="0/10/0/10/10/90",
J="X4i",
Jz=0.1,
p="135/30",
B="",
S="uc",
C="gray",
t="",
)
fig_test.plot3d(
x=x,
y=y,
z=z,
region=[0, 10, 0, 10, 10, 90],
projection="X4i",
zscale=0.1,
perspective=[135, 30],
frame=True,
style="uc",
color=color,
sizes=size,
cmap="gray",
transparency=transparency,
)
return fig_ref, fig_test


@check_figures_equal()
def test_plot3d_matrix(data, region):
"Plot the data passing in a matrix and specifying columns"
Expand Down Expand Up @@ -438,10 +558,7 @@ def test_plot3d_scalar_xyz():
with GMTTempFile() as tmpfile:
np.savetxt(tmpfile.name, np.c_[[-1.5, 0, 1.5], [1.5, 0, -1.5], [-1.5, 0, 1.5]])
fig_ref.basemap(
R="-2/2/-2/2/-2/2",
B=["xaf+lx", "yaf+ly", "zaf+lz"],
Jz=2,
p="225/30",
R="-2/2/-2/2/-2/2", B=["xaf+lx", "yaf+ly", "zaf+lz"], Jz=2, p="225/30"
)
fig_ref.plot3d(data=tmpfile.name, S="c1c", G="red", Jz="", p="", qi=0)
fig_ref.plot3d(data=tmpfile.name, S="t1c", G="green", Jz="", p="", qi=1)
Expand Down

0 comments on commit cdcd259

Please sign in to comment.