Setting tick colors of matplotlib 3D plot

ぐ巨炮叔叔 提交于 2019-12-01 19:41:43

As mentioned in manual page about tick_params(axis='both', **kwargs) you get a bug:

While this function is currently implemented, the core part of the Axes3D object may ignore some of these settings. Future releases will fix this. Priority will be given to those who file bugs.

To override this problem use inner _axinfo dictionary as in this example:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt

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

ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))

ax.xaxis._axinfo['tick']['color']='r'
ax.yaxis._axinfo['tick']['color']='r'
ax.zaxis._axinfo['tick']['color']='r'
plt.show()

A straightforward way to achieve the expected result is as follows:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import rcParams
from matplotlib import pyplot as plt

rcParams['xtick.color'] = 'red'
rcParams['ytick.color'] = 'red'
rcParams['axes.labelcolor'] = 'red'
rcParams['axes.edgecolor'] = 'red'

fig = plt.figure()
ax = Axes3D(fig)

ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))
plt.show()

The output display is:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!