How to make inline plots in Jupyter Notebook larger?

后端 未结 9 1579
慢半拍i
慢半拍i 2020-12-12 08:38

I have made my plots inline on my Ipython Notebook with \"%matplotlib inline.\"

Now, the plot appears. However, it is very small. Is there a way to ma

相关标签:
9条回答
  • 2020-12-12 08:55

    To adjust the size of one figure:

    import matplotlib.pyplot as plt
    
    fig=plt.figure(figsize=(15, 15))
    

    To change the default settings, and therefore all your plots:

    import matplotlib.pyplot as plt
    
    plt.rcParams['figure.figsize'] = [15, 15]
    
    
    0 讨论(0)
  • 2020-12-12 08:56

    using something like:

    import matplotlib.pyplot as plt
    %matplotlib inline
    plt.subplots(figsize=(18,8 ))
    plt.subplot(1,3,1)
    plt.subplot(1,3,2)
    plt.subplot(1,3,3)
    

    The output of the command

    0 讨论(0)
  • 2020-12-12 08:57

    A quick fix to "plot overlap" is to use plt.tight_layout():

    Example (in my case)

    for i,var in enumerate(categorical_variables):
        plt.title(var)
        plt.xticks(rotation=45)
        df[var].hist()
        plt.subplot(len(categorical_variables)/2, 2, i+1)
    
    plt.tight_layout()
    
    0 讨论(0)
  • 2020-12-12 08:58

    If you only want the image of your figure to appear larger without changing the general appearance of your figure increase the figure resolution. Changing the figure size as suggested in most other answers will change the appearance since font sizes do not scale accordingly.

    import matplotlib.pylab as plt
    plt.rcParams['figure.dpi'] = 200
    
    0 讨论(0)
  • 2020-12-12 09:04

    Yes, play with figuresize and dpi like so (before you call your subplot):

    fig=plt.figure(figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
    

    As @tacaswell and @Hagne pointed out, you can also change the defaults if it's not a one-off:

    plt.rcParams['figure.figsize'] = [12, 8]
    plt.rcParams['figure.dpi'] = 100 # 200 e.g. is really fine, but slower
    
    0 讨论(0)
  • 2020-12-12 09:08

    The default figure size (in inches) is controlled by

    matplotlib.rcParams['figure.figsize'] = [width, height]
    

    For example:

    import matplotlib.pyplot as plt
    plt.rcParams['figure.figsize'] = [10, 5]
    

    creates a figure with 10 (width) x 5 (height) inches

    0 讨论(0)
提交回复
热议问题