Python Matplotlib 样式文件:仅显示水平网格线

Ano*_*erd 5 python matplotlib

我试图定义一个 matplotlib 样式文件(.mplstyle)以仅显示水平网格线。我知道我可以用 python 来做

fig, ax = plt.subplots() 
ax.yaxis.grid(True)
Run Code Online (Sandbox Code Playgroud)

但我想在 mplstyle 文件中执行此操作。classic.mplstyle文件具有选项集axes.grid.axis: both。我尝试将其更改为axes.grid.axis: y,但这似乎没有改变任何东西。

是否可以在样式文件中执行此操作?

编辑:

尝试让它发挥作用:

%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
month = ['Jan', 'Feb', 'Mar', 'Apr']
volume = [1, 2, 3, 4]
plt.style.use('https://gist.githubusercontent.com/luisdelatorre012/b36899e6dca07d05e73aca80eceb3098/raw/43ae73605b5e33dfc3f0d7e5d423ff997fc8325c/tiny.mplstyle')
d = pd.DataFrame({'Month': month, 'Volume': volume})
fig, ax = plt.subplots()
b = d.plot(kind='bar', y="Volume", x="Month", ax=ax)
plt.title('Title')
plt.show()
Run Code Online (Sandbox Code Playgroud)

文件tiny.mplstyle包含

axes.grid.axis: y
axes.grid: True
Run Code Online (Sandbox Code Playgroud)

没有别的。

这是结果:

网格线

Imp*_*est 4

你还需要打开网格,

import matplotlib.pyplot as plt
plt.rcParams["axes.grid.axis"] ="y"
plt.rcParams["axes.grid"] = True
Run Code Online (Sandbox Code Playgroud)

或在 matplotlibrc 文件中:

axes.grid.axis : y
axes.grid : True
Run Code Online (Sandbox Code Playgroud)