2D坐标系
1 修改全部坐标颜色
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
x=np.linspace(-1,1,50)
y=x**2
plt.plot(x,y,)
plt.tick_params(axis='x',colors='red')
plt.tick_params(axis='y',colors='red')
plt.show()
2 修改某一点坐标颜色
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5,4))
ax.plot([1,2,3])
ax.get_xticklabels()[3].set_color("red")
ax.get_yticklabels()[5].set_color("red")
plt.show()
3D坐标系
1 修改全部坐标颜色
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig=plt.figure(num=1,figsize=(8,6))
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = np.cos(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'),edgecolors='black')
ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.get_cmap('rainbow'))
ax.set_zlim(-2, 2)
ax.tick_params(axis='x',colors='red')
ax.tick_params(axis='y',colors='red')
ax.tick_params(axis='z',colors='red')
plt.show()
2 修改某一点坐标颜色
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig=plt.figure(num=1,figsize=(8,6))
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = np.cos(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'),edgecolors='black')
ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.get_cmap('rainbow'))
ax.set_zlim(-2, 2)
ax.get_xticklabels()[3].set_color("red")
ax.get_yticklabels()[5].set_color("red")
ax.get_zticklabels()[7].set_color("red")
plt.show()