How to change the figure size of a seaborn axes or figure level plot
You can change the figure size of a Seaborn plot by using the set_size_inches() method of the matplotlib.pyplot.figure object and passing in the desired width and height.
You can change the figure size of a Seaborn plot by using the set_size_inches() method of the matplotlib.pyplot.figure object and passing in the desired width and height. Here is an example:
Change the figure size of a Seaborn plot
import seaborn as sns
import matplotlib.pyplot as plt
width = 10
height = 6
# Generate a Seaborn plot
sns.lineplot(x=..., y=...)
# Get the current figure and set its size
fig = plt.gcf()
fig.set_size_inches(width, height)
# Show the plot
plt.show()
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
You can also use the figure parameter of the seaborn plotting functions to set the size of the figure.
Set the size of the figure with figure parameter
import seaborn as sns
import matplotlib.pyplot as plt
width = 10
height = 6
# Generate a Seaborn plot
sns.lineplot(x=..., y=..., figure=plt.figure(figsize=(width, height)))
plt.show()Note that the units are inches. set_size_inches() accepts width and height as separate arguments, while figsize expects them as a tuple.