不幸的是,这似乎并未公开。查看源代码,关键的内部变量是调用_AXINFO
,我们可以通过仔细的子类来覆盖。
![enter image description here](https://i.stack.imgur.com/Mv096.png)
添加该代码创建你的身材后,和风格也与字典custom_AXINFO
:
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.axis3d as axis3d
# New axis settings
custom_AXINFO = {
'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2),
'color': (0.00, 0.00, 0.25, .75)},
'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2),
'color': (0.20, 0.90, 0.90, 0.25)},
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1),
'color': (0.925, 0.125, 0.90, 0.25)},}
class custom_XAxis(axis3d.Axis):
_AXINFO = custom_AXINFO
class custom_YAxis(axis3d.Axis):
_AXINFO = custom_AXINFO
class custom_ZAxis(axis3d.Axis):
_AXINFO = custom_AXINFO
class custom_Axes3D(Axes3D):
def _init_axis(self):
'''Init 3D axes; overrides creation of regular X/Y axes'''
self.w_xaxis = custom_XAxis('x', self.xy_viewLim.intervalx,
self.xy_dataLim.intervalx, self)
self.xaxis = self.w_xaxis
self.w_yaxis = custom_YAxis('y', self.xy_viewLim.intervaly,
self.xy_dataLim.intervaly, self)
self.yaxis = self.w_yaxis
self.w_zaxis = custom_ZAxis('z', self.zz_viewLim.intervalx,
self.zz_dataLim.intervalx, self)
self.zaxis = self.w_zaxis
for ax in self.xaxis, self.yaxis, self.zaxis:
ax.init3d()
# The rest of your code below, note the call to our new custom_Axes3D
points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose()
fig = plt.figure(figsize = (10,10))
ax = custom_Axes3D(fig)
这是猴子修补它是最差的,并且不应被依赖为更高版本工作。
固定面部颜色比网格线更容易,因为这需要覆盖一个__init__
方法,尽管它可以用更多的工作完成。
将这件事暴露给最终用户似乎并不困难,因此我可以想象这可能会在以后的版本中得到修复。
它看起来像现在,你可以做ax.w_xaxis.plane.set_color((1,0,0)); ax.w_xaxis.plane.set_alpha(0.5)。它看起来像忽略了set_color中的alpha通道,但使用了set_alpha中的通道。 – Ben