pythonmatplotlibgridlinesmatplotlib-3d

How to color 3D gridlines


I was looking for a way to change the color of a 3D plots gridlines and was unable to find a clean and easy way to do so. The only answer I found was here and it came off as a bit complex. I was wondering if there was an easier way to color the gridlines of a 3D plot in matplotlib using mpl_toolkits.mplot3d

simple example found 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()

Solution

  • The code from the question you found is so complex because it colorizes single lines of the grid.

    If the aim is to colorize all gridlines simulatneously, you may just use

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

    enter image description here