我用 Python 中的一些数据绘制了曲面图。
现在我试图改变这样一个情节的风格。但不幸的是,我陷入了线条颜色。它默认为黑色,但我想将其设为红色或任何其他颜色。
我的代码是:
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
最佳答案
如何找到所需的关键字:
plot_surface方法创建一个 Poly3DCollection这是基于 PolyCollections .后者接收关键字,如 edgecolors
(或 facecolors
)。
在你的例子中:
ax.plot_surface(x,y,U,rstride=1,cstride=1,alpha=0,linewidth=0.5, edgecolors='r')
关于python - 更改 plot_surface 中的线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21418255/