2014-01-28 210 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也可以。