# How to change the figure size of a seaborn axes or figure level plot

How do I change the size of my image so it's suitable for printing?

For example, I'd like to use to A4 paper, whose dimensions are 11.7 inches by 8.27 inches in landscape orientation.

You can also set figure size by passing dictionary to `rc` parameter with key `'figure.figsize'` in seaborn `set` method:

``````import seaborn as sns

sns.set(rc={'figure.figsize':(11.7,8.27)})
``````

Other alternative may be to use `figure.figsize` of `rcParams` to set figure size as below:

``````from matplotlib import rcParams

# figure size in inches
rcParams['figure.figsize'] = 11.7,8.27
``````

More details can be found in matplotlib documentation

• Unlike other solutions, this solution doesn't assume a certain way of defining the plot. Thanks. Sep 9, 2018 at 3:02
• Note that when you call sns.set(), it defaults your figure styles to the sns default instead of the matplotlib default, for example your figures would then suddenly have a grey background with white grid – see here: seaborn.pydata.org/tutorial/aesthetics.html. Also, this didn't have any effect on the size of my plot (a sns.pairplot). Oct 24, 2018 at 8:00
• Nor mine as a sns.boxplot Aug 15, 2019 at 10:10
• Thanks for that @Melissa. This made me realise I have to call `.set()` before `.set_style()` Apr 16, 2020 at 13:01
• Alas they both don't produce any plot in Jupyter Lab. `fig, ax = pyplot.subplots(figsize=(20, 2)); a = sns.lineplot(ax=ax, x=..., y=...)` instead works as expected. I am always surprised when such parameters, that should be straightforward in seaborn because used very often, need to be set using "tricks". Jul 13, 2020 at 8:58

You need to create the matplotlib Figure and Axes objects ahead of time, specifying how big the figure is:

``````from matplotlib import pyplot
import seaborn

import mylib

a4_dims = (11.7, 8.27)
fig, ax = pyplot.subplots(figsize=a4_dims)
seaborn.violinplot(ax=ax, data=df, **violin_options)
``````
• this solution does not seem to work with the code that follows (different kind of plot). Any ideas? I assume "mylib" is just a library where you stored your data and is not needed in this code: ` fig, ax = pyplot.subplots(figsize=(12,6)); sns.jointplot(memoryPrice['price'], memoryPrice['Memory']) `
– TMWP
Aug 1, 2017 at 3:25
• This answer doesn't work in @TMWP's case because jointplot is a figure level method. See answer below.
– elz
Aug 1, 2018 at 14:04
• this answer doesn't work with those plot types that don't accept ax as an input, for example `sns.lmplot()`
– F.S.
Sep 25, 2018 at 0:28
• Plot size in seaborn should be set using the `height` and `aspect` parameters as explained here stackoverflow.com/a/51602446/2412831 Sep 10, 2019 at 12:38
• @LeandroOrdonez that's not really applicable to axes-level function. Sep 10, 2019 at 15:03

Note that if you are trying to pass to a "figure level" method in seaborn (for example `lmplot`, `catplot` / `factorplot`, `jointplot`) you can and should specify this within the arguments using `height` and `aspect`.

``````sns.catplot(data=df, x='xvar', y='yvar',
hue='hue_bar', height=8.27, aspect=11.7/8.27)
``````

See https://github.com/mwaskom/seaborn/issues/488 and Plotting with seaborn using the matplotlib object-oriented interface for more details on the fact that figure level methods do not obey axes specifications.

• This is the only answer so far that correctly deals with sns plots that don't accept ax as an argument. Oct 24, 2018 at 7:56
• Note that height and aspect control the dimensions of a single "facet," i.e. a subplot. So this doesn't directly adjust the full figure dimensions. Jan 22, 2020 at 3:39
• Note: this applies to `relplot` too. Even when creating a figure ahead of time using `plt.figure(figsize=...)`, I still needed to specify `height`/`aspect` to get the dimensions to change. I prefer this much more than the `sns.set()` solution because I want different values for different plots. Nov 10, 2022 at 14:33

first import matplotlib and use it to set the size of the figure

``````from matplotlib import pyplot as plt
import seaborn as sns

plt.figure(figsize=(15,8))
ax = sns.barplot(x="Word", y="Frequency", data=boxdata)
``````
• This solution is much simpler
– Nemo
Dec 6, 2022 at 2:36

You can set the context to be `poster` or manually set `fig_size`.

``````import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

np.random.seed(0)
n, p = 40, 8
d = np.random.normal(0, 2, (n, p))
d += np.log(np.arange(1, p + 1)) * -5 + 10

# plot
sns.set_style('ticks')
fig, ax = plt.subplots()
# the size of A4 paper
fig.set_size_inches(11.7, 8.27)
sns.violinplot(data=d, inner="points", ax=ax)
sns.despine()

fig.savefig('example.png')
`````` • this answer doesn't work with those plot types that don't accept ax as an input, for example `sns.lmplot()`
– F.S.
Sep 25, 2018 at 0:29
• To expand on Chris's answer, some seaborn plots generate composite figures with multiple axes, so they CAN'T take a single axis as an argument. Nov 13, 2018 at 16:43
• This worked for me when trying to plot a violinplot. I was able to change the size of the figure inline in a Jupiter lab notebook. Jul 15, 2020 at 18:51

This can be done using:

``````plt.figure(figsize=(15,8))
``````

In addition to elz answer regarding "figure level" methods that return multi-plot grid objects it is possible to set the figure height and width explicitly (that is without using aspect ratio) using the following approach:

``````import seaborn as sns

g = sns.catplot(data=df, x='xvar', y='yvar', hue='hue_bar')
g.fig.set_figwidth(8.27)
g.fig.set_figheight(11.7)
``````
• `set_figwidth` and `set_figheight` work well for grid objects. >>> import seaborn >>> import matplotlib.pyplot as pyplot >>> tips = seaborn.load_dataset("tips") >>> g = seaborn.FacetGrid(tips, col="time", row="smoker") >>> g = g.map(pyplot.hist, "total_bill") >>> g.fig.set_figwidth(10) >>> g.fig.set_figheight(10) Dec 2, 2019 at 16:30
• Perhaps the API changed, but for me it was g.figure.set_figwidth instead of g.fig.set_figwidth. I'm using matplotlib version 3.1.0 and seaborn 0.9.0 Jan 23, 2020 at 19:54
• works with seaborn version `0.11.1` - the other solutions on this page didn't work Feb 23, 2021 at 13:51
• Thank you so much, this is the only solution that has worked for me. Been trying to figure this out for like 15 minutes now
– Nick
May 19, 2021 at 2:50
• 15 minutes? Try 15 hours Jul 28, 2022 at 18:31

This shall also work.

``````from matplotlib import pyplot as plt
import seaborn as sns

plt.figure(figsize=(15,16))
sns.countplot(data=yourdata, ...)
``````

For my plot (a sns factorplot) the proposed answer didn't works fine.

Thus I use

``````plt.gcf().set_size_inches(11.7, 8.27)
``````

Just after the plot with seaborn (so no need to pass an ax to seaborn or to change the rc settings).

• This is the only solution that works for me with a FacetGrid `python g = sns.FacetGrid(df.set_index('category'), col="id") pyplot.gcf().set_size_inches(11.7, 8.27) g.map(lambda data, color: data.plot.barh(color=color), "count") ` Aug 16, 2019 at 8:26
• Same here. It seems like `sns.FacetGrid` would set a figure size according to a calculated value (set by `height` and `aspect`) and changing the figure size directly after seaborn plotting will work. And other fine tuning of the plot can happen after changing the figure size Dec 12, 2019 at 22:47

## Imports and Data

``````import seaborn as sns
import matplotlib.pyplot as plt

``````

## `sns.displot`

• The size of a figure-level plot can be adjusted with the `height` and/or `aspect` parameters
• Additionally, the `dpi` of the figure can be set by accessing the `fig` object and using `.set_dpi()`
``````p = sns.displot(data=df, x='flipper_length_mm', stat='density', height=4, aspect=1.5)
p.fig.set_dpi(100)
``````
• Without `p.fig.set_dpi(100)` • With `p.fig.set_dpi(100)` ## `sns.histplot`

• The size of an axes-level plot can be adjusted with `figsize` and/or `dpi`
``````# create figure and axes
fig, ax = plt.subplots(figsize=(6, 5), dpi=100)

# plot to the existing fig, by using ax=ax
p = sns.histplot(data=df, x='flipper_length_mm', stat='density', ax=ax)
``````
• Without `dpi=100` • With `dpi=100` ``````# Sets the figure size temporarily but has to be set again the next plot
plt.figure(figsize=(18,18))

sns.barplot(x=housing.ocean_proximity, y=housing.median_house_value)
plt.show()
`````` • `plt.figure(figsize=(X,Y))` does nothing, at least with the Jupyter extension in VS Code and seaborn 0.12.2 2 hours ago

Some tried out ways:

``````import seaborn as sns
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=[15,7])
sns.boxplot(x="feature1", y="feature2",data=df, ax=ax) # where df would be your dataframe
``````

or

``````import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=[15,7])
sns.boxplot(x="feature1", y="feature2",data=df) # where df would be your dataframe
``````

The top answers by Paul H and J. Li do not work for all types of seaborn figures. For the `FacetGrid` type (for instance `sns.lmplot()`), use the `size` and `aspect` parameter.

`Size` changes both the height and width, maintaining the aspect ratio.

`Aspect` only changes the width, keeping the height constant.

You can always get your desired size by playing with these two parameters.
{"ft_lang_label":"__label__en","ft_lang_prob":0.66951233,"math_prob":0.8778622,"size":6610,"snap":"2023-14-2023-23","text_gpt3_token_len":1803,"char_repetition_ratio":0.13851045,"word_repetition_ratio":0.10118407,"special_character_ratio":0.27912253,"punctuation_ratio":0.18920814,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9984407,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,6,null,4,null,4,null,4,null,4,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-06T06:05:44Z\",\"WARC-Record-ID\":\"<urn:uuid:8730539d-8720-4683-9b56-50d47a5d2d89>\",\"Content-Length\":\"309286\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:22568a02-b2c8-40c6-bf09-66f0cf9c274f>\",\"WARC-Concurrent-To\":\"<urn:uuid:5023342f-758a-4402-b448-07881df8f150>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://stackoverflow.com/questions/31594549/how-to-change-the-figure-size-of-a-seaborn-axes-or-figure-level-plot\",\"WARC-Payload-Digest\":\"sha1:BHXBVDCECPS3N36FYJBPXVKG3YD2EDPK\",\"WARC-Block-Digest\":\"sha1:4B6UCWGUNHC52QAU3XVUTOVY4TIPBHPR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224652235.2_warc_CC-MAIN-20230606045924-20230606075924-00228.warc.gz\"}"}