And*_*rew 104 python grid matplotlib
在Matplotlib中,我按如下方式制作虚线网格线:
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
ax.yaxis.grid(color='gray', linestyle='dashed')
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何(或者甚至可能)使网格线在其他图形元素(如条形图)后面绘制.更改添加网格与添加其他元素的顺序没有区别.
是否有可能使网格线出现在其他所有的后面?
and*_*oke 101
根据这个 - http://old.nabble.com/axis-elements-and-zorder-td6119088.html - 你可以使用Axis.set_axisbelow(True)
(我目前安装matplotlib的第一次,所以不知道如果这是正确的 - 我只是觉得通过谷歌搜索"matplotlib Z顺序电网" - "Z顺序"通常用来形容这种事情(z是轴"在页面外"))
Ste*_*fan 73
对我来说,目前还不清楚如何应用andrew cooke的答案,所以这是一个完整的解决方案,基于:
ax.set_axisbelow(True)
ax.yaxis.grid(color='gray', linestyle='dashed')
Run Code Online (Sandbox Code Playgroud)
Syr*_*jor 25
如果要验证所有数字的设置,可以设置
plt.rc('axes', axisbelow=True)
Run Code Online (Sandbox Code Playgroud)
要么
plt.rcParams['axes.axisbelow'] = True
Run Code Online (Sandbox Code Playgroud)
它适用于Matplotlib> = 2.0.
我有同样的问题,以下工作:
[line.set_zorder(3) for line in ax.lines]
fig.show() # to update
Run Code Online (Sandbox Code Playgroud)
提高3到一个更高的值,如果它不能正常工作.
您还可以将zorderkwarg 设置为matplotlib.pyplot.grid
plt.grid(which='major', axis='y', zorder=-1.0)
Run Code Online (Sandbox Code Playgroud)