Note that there are some explanatory texts on larger screens.

plurals
  1. POColor matplotlib plot_surface command with surface gradient
    primarykey
    data
    text
    <p>I would like to convert surf command from <strong>MATLAB</strong> to plot_surface command in <strong>matplotlib</strong>.</p> <p>The challenge I am facing is when using <em>cmap</em> function in plot_surface command to color the surface with gradient.</p> <p>Here is the <strong>matlab</strong> script</p> <pre><code>% Matlab Commands x = -5:.25:5; y = x [x,y] = meshgrid(x); R = sqrt(x.^2 + y.^2); Z = sin(R) surf(x,y,Z,gradient(Z)) </code></pre> <p>The figure from such a command can be found here. <a href="http://www.mathworks.com/help/techdoc/visualize/f0-18164.html#f0-46458">(http://www.mathworks.com/help/techdoc/visualize/f0-18164.html#f0-46458)</a></p> <p>Here is the <strong>python</strong> scipt When using python and matplotlib to create a similar function I am unable to color the surface with a gradient. </p> <pre><code># Python-matplotlib Commands from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.gca(projection='3d') X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=gradient(Z), linewidth=0, antialiased=False) plt.show() </code></pre> <p>I get the following error message: </p> <pre><code>Traceback (most recent call last): File "&lt;ipython console&gt;", line 1, in &lt;module&gt; File "C:\Python26\lib\site-packages\spyderlib\widgets\externalshell\startup.py", line 122, in runfile execfile(filename, glbs) File "C:\Documents and Settings\mramacha\My Documents\Python\Candela\tmp.py", line 13, in &lt;module&gt; surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=gradient(Z), linewidth=0, antialiased=False) File "C:\Python26\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 729, in plot_surface polyc = art3d.Poly3DCollection(polys, *args, **kwargs) File "C:\Python26\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 344, in __init__ PolyCollection.__init__(self, verts, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\collections.py", line 570, in __init__ Collection.__init__(self,**kwargs) File "C:\Python26\lib\site-packages\matplotlib\collections.py", line 86, in __init__ cm.ScalarMappable.__init__(self, norm, cmap) File "C:\Python26\lib\site-packages\matplotlib\cm.py", line 155, in __init__ self.cmap = get_cmap(cmap) File "C:\Python26\lib\site-packages\matplotlib\cm.py", line 126, in get_cmap if name in cmap_d: TypeError: unhashable type: 'list' </code></pre> <p>Any inputs would be helpful. </p> <p>Praboo</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload