Matplotlib颜色3D网格线

时间:2017-11-02 21:33:29

标签: python matplotlib 3d

我一直在寻找一种方法来改变3D绘图网格线的颜色,但却无法找到一种干净简单的方法。我找到的唯一答案是here,它有点复杂。我想知道是否有一种更简单的方法可以使用mpl_toolkits.mplot3d

在matplotlib中为3D绘图的网格线着色

找到here

的简单示例
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize'] = 10

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()

plt.show()

1 个答案:

答案 0 :(得分:2)

来自question you found的代码非常复杂,因为它会为网格的单行着色。

如果目标是同时着色所有网格线,您可以使用

plt.rcParams['grid.color'] = "deeppink"

enter image description here