如果我有3D matplotlib图(Axes3D对象),如何更改刻度线的颜色?我想出了如何更改轴线,刻度标签和轴标签的颜色.显而易见的解决方案,使用ax.tick_params(axis =’x’,colors =’red’),只更改刻度标签而不是刻度标记本身.
以下是尝试将所有轴更改为红色并获取除刻度标记之外的所有轴的代码:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))
ax.w_xaxis.line.set_color('red')
ax.w_yaxis.line.set_color('red')
ax.w_zaxis.line.set_color('red')
ax.w_zaxis.line.set_color('red')
ax.xaxis.label.set_color('red')
ax.yaxis.label.set_color('red')
ax.zaxis.label.set_color('red')
ax.tick_params(axis='x', colors='red') # only affects
ax.tick_params(axis='y', colors='red') # tick labels
ax.tick_params(axis='z', colors='red') # not tick marks
fig.show()