使用seaborn distp设置轴最大值

2024-05-16 15:58:45 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以设置seaborn Distlots的最小和最大显示限制?

我试图在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()两种方法,但都没有成功。我错过了什么?


Tags: 数据inpandasdfforvarpltseaborn
1条回答
网友
1楼 · 发布于 2024-05-16 15:58:45

您应该可以通过直接使用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

相关问题 更多 >