Ask Your Question
0

Use colormap for a 3dlistplot?

asked 2019-02-10 06:09:56 +0100

watcher00090 gravatar image

updated 2019-02-10 13:57:48 +0100

FrédéricC gravatar image

How can I plot a list of points in space where the points are colored by their height?

The following code:

biglist = [(0, 0, 12), (0, 1, 19), (0, 2, 24), (0, 3, 30), (0, 4, 33), (0, 5, 35),
(0, 6, 38), (0, 7, 40), (0, 8, 41), (0, 9, 43), (0, 10, 44), (0, 11,
44), (0, 12, 44), (0, 13, 44)]

cm = colormaps.autumn
cf = lambda (x,y,z): z/100 % 1

list_plot3d(biglist, color=(cm,cf), point_list=True)

produces the following error:

/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2\
.7/site-packages/matplotlib-1.5.1-py2.7-macosx-10.7-x86_64.egg/matplotli\
b/cbook.py:137: MatplotlibDeprecationWarning: The matplotlib.delaunay
module was deprecated in version 1.4. Use matplotlib.tri.Triangulation
instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)
/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2\
.7/site-packages/numpy-1.11.0-py2.7-macosx-10.7-x86_64.egg/numpy/lib/fun\
ction_base.py:2558: RuntimeWarning: invalid value encountered in
true_divide
  c /= stddev[:, None]
/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2\
.7/site-packages/numpy-1.11.0-py2.7-macosx-10.7-x86_64.egg/numpy/lib/fun\
ction_base.py:2559: RuntimeWarning: invalid value encountered in
true_divide
  c /= stddev[None, :]
Traceback (click to the left of this block for traceback)
...
KeyError: 'popitem(): dictionary is empty'
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-02-10 11:29:45 +0100

rburing gravatar image

The documentation of list_plot3d states that it returns

A 3-dimensional plot of a surface defined by the list v of points in 3-dimensional space.

So this is not the function you're looking for. (Maybe there could be a more helpful error message, though.)

Instead, plot individual points with point3d and sum the plots:

colorbyheight = lambda (x,y,z): tuple(colormaps.autumn(z/50)[0:3])
sum(point3d(P, color=colorbyheight(P)) for P in biglist)

Here you want the argument of the colormap to range from 0 to 1 (I chose z/50.)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-02-10 06:09:56 +0100

Seen: 255 times

Last updated: Feb 10 '19