python画图颜色代码_python – 用于matplotlib plot_surface命令的颜色栏

保罗帮忙修改了我的应用程序的mplot3d

example code。代码如下:

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

u = np.linspace(0, 2 * np.pi, 100)

v = np.linspace(0, np.pi, 100)

x = 10 * np.outer(np.cos(u), np.sin(v))

y = 10 * np.outer(np.sin(u), np.sin(v))

z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))

z1 = z*cos(0.5*x)

N = z1/z1.max() # normalie 0..1

surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=cm.jet(N), linewidth=0, antialiased=False, shade=False)

fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

该代码很好地绘制了曲面。但是当我尝试添加一个颜色栏到上面的情节,我得到以下错误:

Traceback (most recent call last):

File "", line 1, in

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\test.py", line 22, in

fig.colorbar(surf, shrink=0.5, aspect=5)

File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1104, in colorbar

cb = cbar.Colorbar(cax, mappable, **kw)

File "C:\Python26\lib\site-packages\matplotlib\colorbar.py", line 706, in __init__

mappable.autoscale_None() # Ensure mappable.norm.vmin, vmax

File "C:\Python26\lib\site-packages\matplotlib\cm.py", line 261, in autoscale_None

raise TypeError('You must first set_array for mappable')

TypeError: You must first set_array for mappable

如果有人能够指导我,我将非常感激。

Prabhu

你可能感兴趣的:(python画图颜色代码)