drh*_*gen 4 python matplotlib mplot3d
如果我有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()
Run Code Online (Sandbox Code Playgroud)
正如提到的手册页有关tick_params(axis='both', **kwargs)你会得到一个错误:
虽然此函数当前已实现,但Axes3D对象的核心部分可能会忽略其中一些设置.未来版本将解决这个问题.优先考虑那些提交错误的人.
要覆盖此问题,请使用内部_axinfo字典,如下例所示:
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |