我正在绘制 pandas 中描述的一些数据文档 https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html#plotting-on-a-secondary-y-axis.
import pandas as pd
import matplotlib.pyplot as plt
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
# plot
ax = df.plot(kind='bar', secondary_y=['col1'])
ax.set_ylabel('Foo')
ax.right_ax.set_ylabel('Bar')
# does not show any effect
ax.grid(True, zorder=0)
ax.right_ax.grid(True, zorder=0)
# does not show any effect
ax.set_axisbelow(True)
# works
ax.right_ax.set_axisbelow(True)
plt.show()
这产生
现在我的问题是我想将网格线隐藏在栏后面。我已经尝试过不同的组合zorder
and set_axisbelow
但这仅适用于“第一个”酒吧。
如何将网格(也可能还有图例)隐藏在栏后面?
提前致谢!
仅启用下部轴的网格。
import pandas as pd
import matplotlib.pyplot as plt
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
# plot
ax = df.plot(kind='bar', secondary_y=['col1'])
ax.set_ylabel('Foo')
ax.right_ax.set_ylabel('Bar')
ax.grid(True)
ax.set_axisbelow(True)
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)