0

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) 
sdptn
  • 11
  • 3

2 Answers2

0

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

Arvind Raghu
  • 408
  • 3
  • 9
  • Thanks it does resize but it also generates together with my graph also an additional blank graph with standard size – sdptn Jul 20 '20 at 12:01
  • Could you add an image of it to your question please, so that I could have a look? – Arvind Raghu Jul 20 '20 at 12:19
  • Fund the solution to the blank figure here https://stackoverflow.com/questions/51826447/how-to-resize-a-catplot-of-kind-swarm-in-seaborn-without-generating-a-second-p catplot already generates a figure and it suggested not to use subplot. I can change the size of the figure using "height" and "aspects" in catplot directly – sdptn Jul 20 '20 at 12:51
0

You can add through Seaborn as:

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