2014-01-28 211 views
8

我用Python中的一些数据做了一个曲面图。更改plot_surface中的线条颜色

enter image description here

现在我试图改变这样的情节的风格。但不幸的是我卡在行颜色。它的默认值是黑色,但我想使它变成红色或任何其他颜色。

我的代码是:

from mpl_toolkits.mplot3d import Axes3D 

import matplotlib.pyplot as plt 
from matplotlib import cm 
import numpy as np 

data=np.loadtxt("test.txt") 


def formateU(data): 
    U = np.zeros((20,20)) 
    for value in data: 
     U[value[0],value[1]] = value[2] 
    return U 

U = formateU(data) 


y,x=np.meshgrid(np.linspace(0.,19,20),np.linspace(0.,19,20)) 

fig = plt.figure() 

ax=plt.axes(projection='3d') 

ax.plot_surface(x,y,U,rstride=1,cstride=1,alpha=0,linewidth=0.5) 

ax.view_init(30, 45) 

plt.savefig("test.png") 

plt.show() 

这似乎是显而易见的,它已经成为一个额外的参数:

ax.plot_surface(x,y,U,rstride=1,cstride=1,alpha=0,linewidth=0.5) 

,但我无法弄清楚。

你能帮助我吗?

的test.txt可在http://www.file-upload.net/download-8564062/test.txt.html

+1

尝试'edgecolors ='r''! – Jakob

+0

它的工作原理!谢谢! – Andy

+0

['plot_surface()'](http://matplotlib.org/mpl_toolkits/mplot3d/api.html#mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface)也使用'color'和'cmap'参数。 – MattDMo

回答

7

如何找到所需要的关键字:
plot_surface方法可以创建基于​​一个Poly3DCollection。后者收到类似edgecolors(或facecolors)的关键字。

在您的例子:

ax.plot_surface(x,y,U,rstride=1,cstride=1,alpha=0,linewidth=0.5, edgecolors='r') 

enter image description here

3

既然你已经设置alpha为零,而不是绘制表面的瓷砖,你可能要考虑使用替代plot_wireframe,其中color集行颜色(而不是像plot_surface中的瓷砖颜色)。

但是正如Jakob所建议的那样,edgecolors也可以。