gpt4 book ai didi

python - 调整 3D Matplotlib 图上的网格线

转载 作者:太空狗 更新时间:2023-10-29 20:38:51 25 4
gpt4 key购买 nike

我正准备进行演示,我有一些 3D matplotlib 图形的示例图形。但是,网格线太亮,无法在投影图像上看到。 example 3D image

我尝试使用适用于二维图形的网格方法:

points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose()
fig = plt.figure(figsize = (10,10))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(points[:,0], points[:,1], points[:,2])
ax.view_init(elev=0., azim=0)
ax.set_ylim([0, 60])
ax.set_zlim([0, 60])
ax.set_xlim([0, 60])
ax.set_zlabel('Cytokine')
ax.set_ylabel('Parameter')
ax.grid(linewidth=20)

但这似乎不适用于 3D 图形。有什么建议吗?

最佳答案

如果您不介意让所有线条变粗,那么您可以调整默认的 rc 设置。

给定一个图表,例如:

enter image description here

我们可以添加:

import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2

增加所有行的默认行宽,结果为:

enter image description here

或者,如果你觉得这看起来很难看,你可以使用:

ax.w_xaxis.gridlines.set_lw(3.0)
ax.w_yaxis.gridlines.set_lw(3.0)
ax.w_zaxis.gridlines.set_lw(3.0)

将每个轴的线宽调整为3.0,产生:

enter image description here

为了更新颜色,让网格线真正弹出,你可以添加:

ax.w_xaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}})
ax.w_yaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}})
ax.w_zaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}})

产生:

enter image description here

这些方法很老套,但据我所知,没有更简单的方法可以达到这些结果!!希望这可以帮助;如果您需要任何进一步的帮助,请告诉我!

关于python - 调整 3D Matplotlib 图上的网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17925545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com