在Matplotlib 2.x中设置3D图的线宽

3

我正在使用较新版本的matplotlib,设置线宽的参数已被删除。他们似乎已经改成在Collections对象中设置,但我找不到方法。

我尝试了他们的示例,更改了线宽:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np


fig = plt.figure()
ax = fig.gca(projection='3d')

# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                       linewidth=10, antialiased=False)

# Customize the z axis.
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

在此输入图片描述

但是如图所示,它并没有将线条添加到我的表面。

有什么新的设置线宽度的方法吗?

谢谢!

1个回答

4

当然,只有存在要显示的线条时,线宽度才能生效。因此,需要指定要显示的线条颜色才能看到它们。

surf = ax.plot_surface(X, Y, Z, cmap="RdYlGn", linewidth=2, edgecolor="limegreen")

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