Seaborn: sns.lmplot doesn't handle ax keyword correctly

Created on 21 Dec 2014  路  6Comments  路  Source: mwaskom/seaborn

import pandas as pd

import pylab as plt
import seaborn as sns
print sns.__version__   # 0.5.1

df = pd.DataFrame({"A":[1,2,3],
                   "B":[4,5,7]})
fig, ax = plt.subplots(1,1)
sns.lmplot("A","B",df,ax=ax)
#sns.regplot("A","B",df,ax=ax) # regplot works as intended
plt.show()

The output with version 0.5.1 looks like:

screenshot from 2014-12-21 15 12 12

docs

Most helpful comment

How can I plot any seaborn scatter plot that supports subplots and hue????

All 6 comments

See this stackoverflow answer. In short, lmplot doesn't take an ax kwarg.

OK, fair enough, but reading the documentation it appears that it would. From the docs:

kwargs : key, value pairs
Other keyword arguments are pasted to regplot()

which would have me think that ax would be passed along as well. In fact it is passed, somewhat, since we get a second plot. Perhaps you could have lmplot eat the input ax kwargs if it comes in?

If you pass the kwarg ax it should use or not use it -- the current case where it half uses it is inconsistent.

This feature is would very useful.

I wanted to use the hue function from lmplot to build a grid of plots and I couldn't. Also regplot doesn't support the hue argument.

And to be fair, lmplot does take the ax arg from the regplot arguments.

Closed with #566

How can I plot any seaborn scatter plot that supports subplots and hue????

@gibsondanield read the rest of the sentence:

Understanding the difference between regplot() and lmplot() can be a bit tricky. In fact, they are closely related, as lmplot() uses regplot() internally and takes most of its parameters. However, regplot() is an axes-level function, so it draws directly onto an axes (either the currently active axes or the one provided by the ax parameter), while lmplot() is a figure-level function and creates its own figure, which is managed through a FacetGrid.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

btyukodi picture btyukodi  路  3Comments

sofiatti picture sofiatti  路  4Comments

songololo picture songololo  路  4Comments

amelio-vazquez-reina picture amelio-vazquez-reina  路  3Comments

amelio-vazquez-reina picture amelio-vazquez-reina  路  4Comments