用seaborn distplot设置轴最大值

时间:2018-09-02 08:40:59

标签: python pandas seaborn

是否可以设置海浪散布的最小和最大显示限制?

我试图遍历pandas数据框的列,但是我所有的输出都使用相同的轴。

for v in var_list: 
    df[v].dropna(inplace=True) 
    var=df[v].max()
    vstar = v + "_output.png"
    splot = sns.distplot(df[v])
#    sns.plt.xlim(0, var)
    splot.figure.savefig(vstar)
    splot.autoscale()

我已经使用sns.plt.xlim()和autoscale()进行了几次尝试,但似乎都没有成功。我想念什么?

1 个答案:

答案 0 :(得分:4)

直接使用plt.xlim(0, var),您应该就能得到想要的东西:

In [24]: np.random.seed(0)

In [25]: data = np.random.randn(1000)

In [26]: sns.distplot(data)
Out[26]: <matplotlib.axes._subplots.AxesSubplot at 0xfa291967f0>

In [27]: plt.savefig('plot1.png')

enter image description here

In [39]: plt.clf()

In [40]: sns.distplot(data)
Out[40]: <matplotlib.axes._subplots.AxesSubplot at 0xfa291bcd30>

In [41]: plt.xlim(-10, 10)
Out[41]: (-10, 10)

In [42]: plt.savefig('plot2.png')

enter image description here