Set axis maximum with seaborn distplot

Set axis maximum with seaborn distplot



Is it possible to set the minimum and maximum displayed limits for seaborn distplots?



I am trying to loop over columns of a pandas dataframe but all my outputs get the same axes.


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?




1 Answer
1



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')



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





And by the way, if you'd rather use the object oriented API and operate directly on the Axes that sns.distplot returns (which quickly becomes beneficial for more complicated plots), you could also use splot.set_xlim(0, var) prior to saving the figure. The end result is the same
– fuglede
Sep 2 at 9:13



Axes


sns.distplot


splot.set_xlim(0, var)



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)