changing size of seaborn plots and matplotlib library plots in a common way

后端 未结 2 471
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 04:13
from pylab import rcParams
rcParams[\'figure.figsize\'] = (10, 10)

This works fine for histogram plots but not for factor plots. sns.factorplot (.....

2条回答
  •  遥遥无期
    2021-01-24 04:16

    The figure size can be modified by first creating a figure and axis and passing this as a parameter to the seaborn plot:

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns       
    
    fig, ax = plt.subplots(figsize=(10, 10))
    
    df = pd.DataFrame({
        'product' : ['A', 'A', 'A', 'B', 'B', 'C', 'C'], 
        'close' : [1, 1, 0, 1, 1, 1, 0],
        'counts' : [3, 3, 3, 2, 2, 2, 2]})
    
    sns.factorplot(y='counts', x='product', hue='close', data=df, kind='bar', palette='muted', ax=ax)
    plt.close(2)    # close empty figure
    plt.show()
    

    When using an Axis grids type plot, seaborn will automatically create another figure. A workaround is to close the empty second figure.

提交回复
热议问题