Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seaborn: lmplot() got an unexpected keyword argument 'figsize'

Tags:

How do I change the figure size for my lmplot in seaborn?

This is my current code, but apparently figsize isn't accepted.

sns.lmplot(x="x", y="y", hue="category", data=df,fit_reg=False,        markers=["o", "x"], palette="Set1",figsize=(7,7)); 

Thanks.

like image 813
Zachary Nagler Avatar asked Mar 11 '16 20:03

Zachary Nagler


People also ask

What is Seaborn Lmplot?

lmplot() method is used to draw a scatter plot onto a FacetGrid.


2 Answers

Since an lmplot is "figure-level", figsize is determined by two parameters, size and aspect. I think size=7 will do what you want but I may be way off.

Here it is in the docs (search for "Change the height and aspect ratio of the facets"): http://seaborn.pydata.org/generated/seaborn.lmplot.html

Note: I have been endlessly confused by the exact same thing, and it would be really nice for sizing to have a consistent interface.

like image 178
Josh Rumbut Avatar answered Sep 16 '22 14:09

Josh Rumbut


Compare these two ways of setting the size of a chart:

Generating a linear model plot

sns.lmplot(data=conversion, x='Week Index', y='Lead-Ann', height=4, aspect=5) 

Creating figure with a regression plot

plt.figure(figsize=(24,4)) sns.regplot(data=conversion, x='Week Index', y='Lead-Ann') 

The difference is explained the Seaborn documentation: seaborn.lmplot

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. This has a few consequences, namely that regplot() can happily coexist in a figure with other kinds of plots and will follow the global matplotlib color cycle. In contrast, lmplot() needs to occupy an entire figure, and the size and color cycle are controlled through function parameters, ignoring the global defaults.

like image 23
Joe Heffer Avatar answered Sep 19 '22 14:09

Joe Heffer