Python 如何使用seaborn FactoryPlot更改图形大小

Python 如何使用seaborn FactoryPlot更改图形大小,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我总是得到一个小尺寸的数字,无论我在figsize中指定了什么尺寸。。。 如何修复它 不要使用%pylab inline,它已被弃用,请使用%matplotlib inline 这个问题不是IPython独有的 使用seaborn.set_style函数,将其作为第二个参数或kwarg传递给您的rc: 图形的大小由size和aspect到factorplot的参数控制。它们对应于每个面的大小(“size”实际上意味着“高度”,然后size*aspect给出宽度),因此,如果您的目标是整个图形的特

我总是得到一个小尺寸的数字,无论我在figsize中指定了什么尺寸。。。 如何修复它

  • 不要使用
    %pylab inline
    ,它已被弃用,请使用
    %matplotlib inline
  • 这个问题不是IPython独有的
  • 使用seaborn
    .set_style
    函数,将其作为第二个参数或kwarg传递给您的rc:

  • 图形的大小由
    size
    aspect
    factorplot
    的参数控制。它们对应于每个面的大小(“size”实际上意味着“高度”,然后
    size*aspect
    给出宽度),因此,如果您的目标是整个图形的特定大小,则需要从那里向后操作

    2019年添加的注释:在现代seaborn版本中,
    size
    参数已重命名为
    height

    更具体一点:

    %pylab inline
    
    import pandas as pd
    import numpy as np
    import matplotlib as mpl
    import seaborn as sns
    
    typessns = pd.DataFrame.from_csv('C:/data/testesns.csv', index_col=False, sep=';')
    
    mpl.rc("figure", figsize=(45, 10))
    sns.factorplot("MONTH", "VALUE", hue="REGION", data=typessns, kind="box", palette="OrRd");
    
    在构建绘图时,您希望将参数“size”或“aspect”传递给sns.factorplot()

    Size将更改高度,同时保持纵横比(因此,如果仅更改大小,它也将变宽。)

    纵横比将在保持高度不变的同时更改宽度

    上述代码应该能够在ipython笔记本中本地运行

    在这些示例中,为了显示效果,减少了绘图大小,因为上述代码中的绘图在保存为png时相当大。这也表明尺寸/纵横比在页边距中包含图例

    大小=2,纵横比=1

    size=4,aspect=1

    size=4,aspect=2

    此外,加载“sns”模块后,可以使用查看此打印功能的所有其他有用参数/参数和默认值:

    %matplotlib inline
    
    import seaborn as sns
    
    exercise = sns.load_dataset("exercise")
    
    # Defaults are size=5, aspect=1
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=2, aspect=1)
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=1)
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=2)
    

    mpl.rc
    存储在全局字典中(请参阅)。 因此,如果您只想更改一个图形的大小(本地),它将实现以下功能:

    help(sns.factorplot)
    

    使用
    matplotlib-1.4.3
    seaborn-0.5.1

    如果您只想缩放图形,请使用以下代码:

    plt.figure(figsize=(45,10))
    sns.factorplot(...)
    
    注:截至2018年7月:

    seaborn.\uuuuu版本=0.9.0

    影响上述答案的两个主要变化

  • factorplot
    函数已重命名为

  • 对于多打印网格函数和使用它们的网格函数,
    size
    参数已重命名为
    height

  • 这意味着@Fernando Hernandez提供的答案应根据以下内容进行调整:

    import seaborn as sns
    
    sns.set(rc={'figure.figsize':(12.7,8.6)})
    
    plt.figure(figsize=(45,10))
    

    我使用matplotlib和Seaborn的第一天,很抱歉问了这个愚蠢的问题,但是如果不控制图形的大小,
    mpl.rc(“figure”,figsize=(45,10))
    有什么好处呢?我还看到了这里使用的相同的
    mpl.rc
    代码:-并且它不会改变我绘图中的大小。在我尊重与您相同的顺序之前,它对我有效,
    plt。图必须首先显示。感谢您,在这种情况下,您还需要
    将matplotlib.pyplot导入为plt
    @psychemedia我还发现,在大多数情况下,坚持使用“height”参数比导入pyplot更好!这是唯一适合我的解决方案。尝试了所有其他方法,即使没有错误,图形仍然显示为默认大小和纵横比(小而方形)。
    import seaborn as sns
    
    sns.set(rc={'figure.figsize':(12.7,8.6)})
    
    plt.figure(figsize=(45,10))
    
    %matplotlib inline
    
    import seaborn as sns
    
    exercise = sns.load_dataset("exercise")
    
    # Defaults are hieght=5, aspect=1
    sns.catplot("kind", "pulse", "diet", exercise, kind="point", height=4, aspect=2)