10

I am making a plot using seaborn FacetGrid with dataframe: df. I am using sns because of the hue functionality.

See code:

import seaborn as sns
import matplotlib.pyplot as plt 

grid = sns.FacetGrid(df,hue='var')
grid.map(plt.scatter, x, y).add_legend()
grid.set(ylim=ylim,xlim=xlim)
plt.show()

Normally I would access the figsize by using:

fig, ax = plt.subplots(figsize=(20, 10))

or

plt.figure(figsize=(20,10))

But now, because I'm using seaborn, I don't know how to access the figure-object.

How do I access the figure object in order to change the size of the plot?

J.A.Cado
  • 715
  • 5
  • 13
  • 24
  • 2
    https://stackoverflow.com/questions/31594549/how-do-i-change-the-figure-size-for-a-seaborn-plot might help you EDIT: I realise you may also be looking for aspect and size within Seaborn for each facet: size : scalar, optional Height (in inches) of each facet. See also: aspect. aspect : scalar, optional Aspect ratio of each facet, so that aspect * size gives the width of each facet in inches. – Anne Feb 27 '18 at 10:23
  • 1
    Tnx Anne! using size and aspect allowed me to change the size of the figure. However, I am still interested in how to access the figure object when deploying a graph using SeaBorn. Any idea? – J.A.Cado Feb 28 '18 at 02:08
  • Point taken. You can use some functions (https://www.datacamp.com/community/tutorials/seaborn-python-tutorial#figsize) but I have yet to see a function that really returns the figure-object. I am curious to see whether someone else knows a way to do that. – Anne Mar 05 '18 at 11:13
  • 2
    I cannot post an answer, so here we go: In your example, the matplotlib Figure object will be `grid.fig` – LCT Aug 08 '18 at 11:23
  • 3
    You can also use arguments in FacetGrid like height. Example: ```sns.FacetGrid(data=df, col="x", hue="category", height=15)``` – godot Mar 07 '19 at 00:36

0 Answers0