python - 设置 matplotlib 3D 绘图的刻度颜色
问题描述
如果我有 3D matplotlib 图(Axes3D
对象),如何更改刻度线的颜色?我想出了如何更改轴线、刻度标签和轴标签的颜色。显而易见的解决方案 useax.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()
解决方案
如手册页中所述,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()
推荐阅读
- r - Kernel Density Estimate(概率密度函数)错了?
- sql - sql表数据发生变化后如何自动刷新vue.js应用程序?
- php - PHP函数move_upload不会将文件移动到centos 8服务器
- linux - LZOP 1.03 ACC 一致性检查失败
- git - Git报错索引文件太小,上游没了
- excel - 复制一系列单元格并仅将同一范围内的值粘贴到另一张工作表中
- python - OpenCV(4.4.0) 错误:(-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
- mongodb - 获取有权限的用户列表
- flutter - 在 Flutter 上,如何通过在 1 小时后将刷新令牌交换为 id 令牌来保持登录持久性?
- java - 我应该如何设计电子商务类图?