Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何独立设置绘图的水平和垂直、主网格线和次网格线?_Python_Matplotlib_Grid - Fatal编程技术网

Python 如何独立设置绘图的水平和垂直、主网格线和次网格线?

Python 如何独立设置绘图的水平和垂直、主网格线和次网格线?,python,matplotlib,grid,Python,Matplotlib,Grid,我想绘制y轴的主栅格线(水平栅格线),但不想绘制垂直主栅格线(x轴)。相反,我想要绘制垂直的次要网格线 我该怎么做 ax.grid(which='major',linewidth=0)code同时隐藏垂直和水平主网格线 谢谢大家! 网格线属性可以通过ax.xaxis.grid()和ax.yaxis.grid()独立设置 要激活次要轴网线,首先需要为其指定定位器 import matplotlib.pyplot as plt from matplotlib.ticker import Multip

我想绘制y轴的主栅格线(水平栅格线),但不想绘制垂直主栅格线(x轴)。相反,我想要绘制垂直的次要网格线

我该怎么做

ax.grid(which='major',linewidth=0)
code同时隐藏垂直和水平主网格线


谢谢大家!

网格线属性可以通过
ax.xaxis.grid()
ax.yaxis.grid()
独立设置
要激活次要轴网线,首先需要为其指定定位器

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

fig, ax = plt.subplots(figsize=(5,3))

ax.yaxis.grid(which="major", color='r', linestyle='-', linewidth=2)

ml = MultipleLocator(0.02)
ax.xaxis.set_minor_locator(ml)
ax.xaxis.grid(which="minor", color='k', linestyle='-.', linewidth=0.7)

plt.show()