在3D Matplotlib图上调整网格线 [英] Adjusting gridlines on a 3D Matplotlib figure

查看:105
本文介绍了在3D Matplotlib图上调整网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm getting ready for a presentation and I have some example figures of 3D matplotlib figures. However, the gridlines are too light to see on the projected images.

我尝试使用适用于2D图形的网格方法:

I tried using the grid-method that works for 2D figures:

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 图形.有什么建议吗?

But that doesn't seem to work for 3D figures. Any suggestions?

推荐答案

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

If you don't mind having all the lines thicker then you could adjust the default rc settings.

给定一个图表,例如:

我们可以添加:

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

增加所有线的默认线宽,结果如下:

To increase the default line width of all lines, giving a result of:

或者,如果您觉得这看起来很丑,则可以使用:

Alternatively, if you feel this looks ugly, you could use:

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,产生:

to adjust the line width of each axis to 3.0, producing:

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

In order to update the colour, so the grid-lines really pop, you could add:

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)}})

哪个会产生:

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

The methods are pretty hacky, but as far as I am aware there is no simpler way of achieving these results!! Hope this helps; let me know if you require any further assistance!

这篇关于在3D Matplotlib图上调整网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆