在plot_surface中更改线条颜色

10

我使用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找到。


1
尝试使用 edgecolors='r' - Jakob
plot_surface()还可以接受colorcmap参数。 - MattDMo
2个回答

11

如何找到所需的关键词:
plot_surface 方法创建了一个基于 Poly3DCollection 的图像,它基于 PolyCollections。后者接收像 edgecolors(或 facecolors)这样的关键词。

在您的示例中:

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

输入图像描述


3

由于您将 alpha 设置为零并且不绘制表面瓷砖,因此您可能希望考虑改用 plot_wireframe,其中 color 设置线条颜色(而不是像在 plot_surface 中设置瓷砖颜色)。

但正如 Jakob 建议的那样,edgecolors 也可以使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接