Skip to content Skip to sidebar Skip to footer

How To Increase The Size Of The Figure By Percentage But Keep The Original Aspect Ratio?

I have the following code to draw a figure import pandas as pd import urllib3 import seaborn as sns decathlon = pd.read_csv('https://raw.githubusercontent.com/leanhdung1994/Deep-L

Solution 1:

First, the object returned by scatterplot() is an Axes, not a figure. scatterplot() uses the current axes to draw the plot. If there is no current axes, then matplotlib automatically creates one in the current figure. If there is not current figure, then matplotlib automatically creates a new figure.

The size of this figure is determined by the value in rcParams['figure.figsize']. Therefore, you should create a figure that has the same aspect ratio as defined in this variable before calling your plots.

For instance, the code below creates a figure that's 2x the size of the default figure.

tips = sns.load_dataset('tips')

fig = plt.figure(figsize= 2 * np.array(plt.rcParams['figure.figsize']))
ax = sns.scatterplot(data=tips, x="total_bill", y="tip", hue="day")
sns.regplot(data=tips, x="total_bill", y="tip", scatter=False, ax=ax)

Post a Comment for "How To Increase The Size Of The Figure By Percentage But Keep The Original Aspect Ratio?"