How do you change the size of figures drawn with matplotlib?

后端 未结 19 3377
忘掉有多难
忘掉有多难 2020-11-21 06:01

How do you change the size of figure drawn with matplotlib?

19条回答
  •  半阙折子戏
    2020-11-21 06:20

    I always use the following pattern:

    x_inches = 150*(1/25.4)     # [mm]*constant
    y_inches = x_inches*(0.8)
    dpi = 96
    
    fig = plt.figure(1, figsize = (x_inches,y_inches), dpi = dpi, constrained_layout = True)
    

    With this example you are able to set figure dimensions in inches or in milimiters and setting constrained_layout to True plots fill your figure without borders.

提交回复
热议问题