pandas 使用 seaborn distplot 设置轴最大值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52135315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set axis maximum with seaborn distplot
提问by MicrobicTiger
Is it possible to set the minimum and maximum displayed limits for seaborn distplots?
是否可以为 seaborn distplots 设置最小和最大显示限制?
I am trying to loop over columns of a pandas dataframe but all my outputs get the same axes.
我正在尝试遍历 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()
I have made a few attempts with sns.plt.xlim()and autoscale()but neither seems to do the trick. What am I missing?
我与几个尝试sns.plt.xlim()和自动量程(),但也似乎这样的伎俩。我错过了什么?
回答by fuglede
You should be able to get what you want by just using plt.xlim(0, var)
directly:
您应该能够通过直接使用来获得您想要的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')
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')