使用matplotlib制作3D散点图时,我似乎无法控制轴是在图上方还是下方。例如,如果ax1.elev<以下代码将始终在图上方具有x和y轴。 0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure('Test')
X = np.random.rand(1,100)
Y = np.random.rand(1,100)
Z = np.random.rand(1,100)
ax1 = fig.add_subplot(111, projection = '3d')
ax1.scatter(X,Y,Z)
ax1.view_init(-10,45)
即使ax1.elev<也可以强制x和y轴以及网格线和平面低于绘图。 0?
答案 0 :(得分:2)
我以this question的代码为例(感谢crayzeewulf)。除z轴外,我们对x轴和y轴进行
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure('Test')
X = np.random.rand(1,100)
Y = np.random.rand(1,100)*10
Z = np.random.rand(1,100)
ax1 = fig.add_subplot(111, projection = '3d')
ax1.scatter(X,Y,Z)
ax1.view_init(-10,45)
tmp_planes = ax1.zaxis._PLANES
ax1.xaxis._PLANES = ( tmp_planes[3], tmp_planes[2],
tmp_planes[1], tmp_planes[0],
tmp_planes[5], tmp_planes[4])
ax1.yaxis._PLANES = ( tmp_planes[3], tmp_planes[2],
tmp_planes[1], tmp_planes[0],
tmp_planes[5], tmp_planes[4])
view_1 = (25, -135)
view_2 = (-10, 45)
init_view = view_2
ax1.view_init(*init_view)