我想要定义一个matplotlib样式文件(.mplstyle)以仅显示水平网格线。我知道我可以用python做它Python Matplotlib样式文件:仅显示水平网格线
fig, ax = plt.subplots()
ax.yaxis.grid(True)
但我想在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()
文件tiny.mplstyle包含
axes.grid.axis: y
axes.grid: True
,别无其他。
这是结果:
你重新启动Matplotlib? – Joe
@Joe,我在jupyter笔记本中测试了这个,并在重新运行之前重新启动内核,以便多个matplotlib样式文件不会一起应用。这是你指的是什么? – AnonymousCowherd