Improve subplot size/spacing with many subplots in matplotlib

前端 未结 6 1529
一整个雨季
一整个雨季 2020-11-22 12:56

Very similar to this question but with the difference that my figure can be as large as it needs to be.

I need to generate a whole bunch of vertically-stacked plots

6条回答
  •  情歌与酒
    2020-11-22 13:09

    import matplotlib.pyplot as plt
    
    fig = plt.figure(figsize=(10,60))
    plt.subplots_adjust( ... )
    

    The plt.subplots_adjust method:

    def subplots_adjust(*args, **kwargs):
        """
        call signature::
    
          subplots_adjust(left=None, bottom=None, right=None, top=None,
                          wspace=None, hspace=None)
    
        Tune the subplot layout via the
        :class:`matplotlib.figure.SubplotParams` mechanism.  The parameter
        meanings (and suggested defaults) are::
    
          left  = 0.125  # the left side of the subplots of the figure
          right = 0.9    # the right side of the subplots of the figure
          bottom = 0.1   # the bottom of the subplots of the figure
          top = 0.9      # the top of the subplots of the figure
          wspace = 0.2   # the amount of width reserved for blank space between subplots
          hspace = 0.2   # the amount of height reserved for white space between subplots
    
        The actual defaults are controlled by the rc file
        """
        fig = gcf()
        fig.subplots_adjust(*args, **kwargs)
        draw_if_interactive()
    

    or

    fig = plt.figure(figsize=(10,60))
    fig.subplots_adjust( ... )
    

    The size of the picture matters.

    "I've tried messing with hspace, but increasing it only seems to make all of the graphs smaller without resolving the overlap problem."

    Thus to make more white space and keep the sub plot size the total image needs to be bigger.

提交回复
热议问题