Richard.L Richard.L - 1 year ago 177
Python Question

How to use colormap in VisPy surfaceplot

I'm using

to plot a surface, but the function
only has the parameter
,without the parameter
. Does anyone know how to use
in surface plotting?

Answer Source

Currently, there appears to be a bug that's keeping the colors parameter of SurfacePlot from working. Giving the surface anything but a solid color would probably have to go down that path. So it may not be possible at this time without altering the source code.

For what it's worth, I believe the following would work if this bug wasn't present:

import vispy.plot as vp
from vispy import color

fig = vp.Fig(show=False)
cnorm = z / abs(np.amax(z))
colors = color.get_colormap("hsl").map(cnorm).reshape(z.shape + (-1,))
fig[0, 0].surface(z, x=x, y=y, colors=colors)

Basically, you normalize the data to be between 0 and 1, and then map those values to a colormap. This will return a 3D array of RGB colors that you can pass to SurfacePlot's colors parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download