plt.figure not resizing figure

682 views Asked by At

I have this function and I want to change the size of the figure, however whatever values I put in the figsize, the figure size does not change. Can anybody suggest what's the problem? or if there is an alternative way for doing this?

def plot_comparison_barplots(df, bar_col, hue_col, scaled):

    fig = plt.figure(figsize=(12,10))
    fig.set_tight_layout(True)
    plt.rcParams.update({'font.size': 9})
     
    ax = sns.catplot(x=bar_col, y='count in %', data=df, hue=hue_col, kind='bar', order=scaled) 
2

There are 2 answers

3
Arvind Raghu On

There is an easier way to implement this function, by using subplots instead of figure, as when you use the set_tight_layout() method, this automatically changes the location of the axes to make your graph look nicer, and make sure that none of the axis names are cut off. The quickest way of getting around this is to define your axes before the set_tight_layout() method, so that the figsize parameter overrides it.

Change:

fig = plt.figure(figsize=(12,10))

to

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

0
vin On

You can add through Seaborn as:

sns.set(rc={'figure.figsize':(12,10)})