如何在 matplotlib 图中的特定位置添加网格线? [英] How to add a grid line at a specific location in matplotlib plot?

查看:105
本文介绍了如何在 matplotlib 图中的特定位置添加网格线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 matplotlib 图中 y 轴的特定位置添加网格?

How do I add grid at a specific location on the y axis in a matplotlib plot?

推荐答案

是的.这很简单.使用 axes 对象的 set_[x|y]ticks 方法并正常切换网格:

Yes. It's very simple. Use the set_[x|y]ticks methods of axes object and toggle the grid as normal:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_yticks([0.2, 0.6, 0.8], minor=False)
ax.set_yticks([0.3, 0.55, 0.7], minor=True)
ax.yaxis.grid(True, which='major')
ax.yaxis.grid(True, which='minor')
plt.show()

这篇关于如何在 matplotlib 图中的特定位置添加网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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