在使用secondary_y与Seaborn + Pandas进行绘图时,如何摆脱网格线 [英] How to get rid of grid lines when plotting with Seaborn + Pandas with secondary_y
本文介绍了在使用secondary_y与Seaborn + Pandas进行绘图时,如何摆脱网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在绘制两个带有进口的熊猫的数据系列.理想情况下,我希望左右y轴之间共享水平网格线,但我觉得这很难做到.
I'm plotting two data series with Pandas with seaborn imported. Ideally I would like the horizontal grid lines shared between both the left and the right y-axis, but I'm under the impression that this is hard to do.
作为一种折衷,我想一起删除网格线.但是,以下代码将生成辅助y轴的水平网格线.
As a compromise I would like to remove the grid lines all together. The following code however produces the horizontal gridlines for the secondary y-axis.
import pandas as pd
import numpy as np
import seaborn as sns
data = pd.DataFrame(np.cumsum(np.random.normal(size=(100,2)),axis=0),columns=['A','B'])
data.plot(secondary_y=['B'],grid=False)
推荐答案
您可以在绘制后将轴"对象取出并在两个轴上执行.grid(False)
.
You can take the Axes object out after plotting and perform .grid(False)
on both axes.
# Gets the axes object out after plotting
ax = data.plot(...)
# Turns off grid on the left Axis.
ax.grid(False)
# Turns off grid on the secondary (right) Axis.
ax.right_ax(False)
这篇关于在使用secondary_y与Seaborn + Pandas进行绘图时,如何摆脱网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文