python - 更改 plot_surface 中的线条颜色

标签 python numpy matplotlib mplot3d

我用 Python 中的一些数据绘制了曲面图。

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

最佳答案

如何找到所需的关键字:
plot_surface方法创建一个 Poly3DCollection这是基于 PolyCollections .后者接收关键字,如 edgecolors(或 facecolors)。

在你的例子中:

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

enter image description here

关于python - 更改 plot_surface 中的线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21418255/

相关文章:

python - 在 Python GUI 中使用 basemap 作为图形

python - ctypes 不会加载库

python - 如何使用子类的默认值调用父类init?

c++ - cython c++ 对 std::ios_base::failure 的 undefined reference

python - 根据 Python 中其他列的条件创建新列

python - <unknown> 不是 numpy 数组错误

python - 为什么我的代码没有生成两个进程?

python - 在 1 个 I/O channel 中提取 numpy 中的总和字典的最快方法

python - Pandas scatter_matrix - 绘制分类变量

python - 从 Matplotlib 图例中排除 Cartopy 元素