Skip to content

Commit cdcd259

Browse files
committed
Let plot3d accept record by record transparency
1 parent bd07900 commit cdcd259

File tree

3 files changed

+126
-5
lines changed

3 files changed

+126
-5
lines changed

pygmt/base_plotting.py

+4
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,10 @@ def plot3d(
980980
)
981981
extra_arrays.append(sizes)
982982

983+
if "t" in kwargs and is_nonstr_iter(kwargs["t"]):
984+
extra_arrays.append(kwargs["t"])
985+
kwargs["t"] = ""
986+
983987
with Session() as lib:
984988
# Choose how data will be passed in to the module
985989
if kind == "file":

pygmt/tests/test_plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_plot_varying_transparency():
269269

270270
@check_figures_equal()
271271
def test_plot_sizes_colors_transparencies():
272-
"Plot the data using z as transparency"
272+
"Plot the data with varying sizes and colors using z as transparency"
273273
x = np.arange(1.0, 10.0)
274274
y = np.arange(1.0, 10.0)
275275
color = np.arange(1, 10) * 0.15

pygmt/tests/test_plot3d.py

+121-4
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,126 @@ def test_plot3d_colors_sizes_proj(data, region):
307307
return fig_ref, fig_test
308308

309309

310+
@check_figures_equal()
311+
def test_plot3d_transparency():
312+
"Plot the data with a constant transparency"
313+
x = np.arange(1, 10)
314+
y = np.arange(1, 10)
315+
z = np.arange(1, 10) * 10
316+
317+
fig_ref, fig_test = Figure(), Figure()
318+
# Use single-character arguments for the reference image
319+
with GMTTempFile() as tmpfile:
320+
np.savetxt(tmpfile.name, np.c_[x, y, z], fmt="%d")
321+
fig_ref.plot3d(
322+
data=tmpfile.name,
323+
S="u0.2c",
324+
G="blue",
325+
R="0/10/0/10/10/90",
326+
J="X4i",
327+
Jz=0.1,
328+
B="",
329+
p="135/30",
330+
t=80.0,
331+
)
332+
333+
fig_test.plot3d(
334+
x=x,
335+
y=y,
336+
z=z,
337+
style="u0.2c",
338+
color="blue",
339+
region=[0, 10, 0, 10, 10, 90],
340+
projection="X4i",
341+
zscale=0.1,
342+
frame=True,
343+
perspective=[135, 30],
344+
transparency=80.0,
345+
)
346+
return fig_ref, fig_test
347+
348+
349+
@check_figures_equal()
350+
def test_plot3d_varying_transparency():
351+
"Plot the data using z as transparency using 3-D column symbols"
352+
x = np.arange(1, 10)
353+
y = np.arange(1, 10)
354+
z = np.arange(1, 10) * 10
355+
356+
fig_ref, fig_test = Figure(), Figure()
357+
# Use single-character arguments for the reference image
358+
with GMTTempFile() as tmpfile:
359+
np.savetxt(tmpfile.name, np.c_[x, y, z, z, z], fmt="%d")
360+
fig_ref.plot3d(
361+
data=tmpfile.name,
362+
S="o0.2c+B5",
363+
G="blue",
364+
R="0/10/0/10/10/90",
365+
J="X4i",
366+
Jz=0.1,
367+
B="",
368+
p="135/30",
369+
t="",
370+
)
371+
fig_test.plot3d(
372+
x=x,
373+
y=y,
374+
z=z,
375+
style="o0.2c+B5",
376+
color="blue",
377+
region=[0, 10, 0, 10, 10, 90],
378+
projection="X4i",
379+
zscale=0.1,
380+
frame=True,
381+
perspective=[135, 30],
382+
transparency=z,
383+
)
384+
return fig_ref, fig_test
385+
386+
387+
@check_figures_equal()
388+
def test_plot3d_sizes_colors_transparencies():
389+
"Plot the data with varying sizes and colors using z as transparency"
390+
x = np.arange(1.0, 10.0)
391+
y = np.arange(1.0, 10.0)
392+
z = np.arange(1, 10) * 10
393+
color = np.arange(1, 10) * 0.15
394+
size = np.arange(1, 10) * 0.2
395+
transparency = np.arange(1, 10) * 10
396+
397+
fig_ref, fig_test = Figure(), Figure()
398+
# Use single-character arguments for the reference image
399+
with GMTTempFile() as tmpfile:
400+
np.savetxt(tmpfile.name, np.c_[x, y, z, color, size, transparency])
401+
fig_ref.plot3d(
402+
data=tmpfile.name,
403+
R="0/10/0/10/10/90",
404+
J="X4i",
405+
Jz=0.1,
406+
p="135/30",
407+
B="",
408+
S="uc",
409+
C="gray",
410+
t="",
411+
)
412+
fig_test.plot3d(
413+
x=x,
414+
y=y,
415+
z=z,
416+
region=[0, 10, 0, 10, 10, 90],
417+
projection="X4i",
418+
zscale=0.1,
419+
perspective=[135, 30],
420+
frame=True,
421+
style="uc",
422+
color=color,
423+
sizes=size,
424+
cmap="gray",
425+
transparency=transparency,
426+
)
427+
return fig_ref, fig_test
428+
429+
310430
@check_figures_equal()
311431
def test_plot3d_matrix(data, region):
312432
"Plot the data passing in a matrix and specifying columns"
@@ -438,10 +558,7 @@ def test_plot3d_scalar_xyz():
438558
with GMTTempFile() as tmpfile:
439559
np.savetxt(tmpfile.name, np.c_[[-1.5, 0, 1.5], [1.5, 0, -1.5], [-1.5, 0, 1.5]])
440560
fig_ref.basemap(
441-
R="-2/2/-2/2/-2/2",
442-
B=["xaf+lx", "yaf+ly", "zaf+lz"],
443-
Jz=2,
444-
p="225/30",
561+
R="-2/2/-2/2/-2/2", B=["xaf+lx", "yaf+ly", "zaf+lz"], Jz=2, p="225/30"
445562
)
446563
fig_ref.plot3d(data=tmpfile.name, S="c1c", G="red", Jz="", p="", qi=0)
447564
fig_ref.plot3d(data=tmpfile.name, S="t1c", G="green", Jz="", p="", qi=1)

0 commit comments

Comments
 (0)