my matplotlib title gets cropped

后端 未结 3 1129
孤独总比滥情好
孤独总比滥情好 2020-12-28 08:38

SOLVED - see comment below on combining wraptext.wrap and plt.tightlayout.

PROBLEM: Here\'s the code:

import matplotlib.pyp         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 09:18

    You could wrap the text with newline characters (\n) automatically using textwrap:

    >>> longstring = "this is a very long title and therefore it gets cropped which is an unthinkable behaviour as it loses the information in the title"
    >>> "\n".join(textwrap.wrap(longstring, 100))
    'this is a very long title and therefore it gets cropped which is an unthinkable behaviour as it\nloses the information in the title'
    

    In this case, 100 is the number of characters per line (to the nearest whitespace - textwrap tries not to break up words)


    Another option is to reduce the size of the font:

    matplotlib.rcParams.update({'font.size': 12})
    

提交回复
热议问题