Cor*_*yer 2 python matplotlib pandas
我正在绘制熊猫文档中描述的一些数据。
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()
Run Code Online (Sandbox Code Playgroud)
这产生
现在我的问题是我想隐藏酒吧后面的网格线。我已经尝试了zorder和 的不同组合,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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1014 次 |
| 最近记录: |