python - matplotlib 中 3D 散点图上方的网格线

标签 python matplotlib

使用 matplotlib 制作 3D 散点图时,我似乎无法控制轴是在图上方还是下方。例如,如果 ax1.elev < 0

,下面的代码将始终在图上方显示 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)
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 < 0,是否可以强制 x 轴和 y 轴以及网格线和平面低于绘图?

最佳答案

我以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)

Change_axes_pos

关于python - matplotlib 中 3D 散点图上方的网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41687546/

相关文章:

python - 处理两条标记线之间的文本文件行

Python 将字符串解析为字典

python - Seaborn 热图 : underline text in a cell

python - 防止科学记数法

python - 如何设置seaborn箱线图的y轴范围?

Python3 & Opencv3 & Multiprocessing 引发系统错误

python - 交互式条件直方图桶切片数据可视化

python - Django 测试在 Postgresql (8.4) 上失败 - 刷新数据库导致错误

python - 我如何让它在情节上显示图例?

python - 如何绘制列中的某些值(子图)