是否可以在绘图区域内放置刻度标签?我已经尝试过了:
ax.tick_params(axis="y",pad=-.5, left="off",labelleft="on")
Run Code Online (Sandbox Code Playgroud)
和
ax.tick_params(axis="y",direction="in", left="off",labelleft="on")
Run Code Online (Sandbox Code Playgroud)
前者只是向内移动轴,而后者只移动刻度而不是刻度标签.
我试图定义一个 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)
没有别的。
这是结果: