sdptn
sdptn

Reputation: 11

plt.figure not resizing figure

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) 

Upvotes: 0

Views: 922

Answers (2)

vin
vin

Reputation: 1

You can add through Seaborn as:

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

Upvotes: 0

Arvind Raghu
Arvind Raghu

Reputation: 458

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))

Upvotes: 0

Related Questions