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

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

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

19条回答
  •  滥情空心
    2020-11-21 06:23

    Since Matplotlib isn't able to use the metric system natively, if you want to specify the size of your figure in a reasonable unit of length such as centimeters, you can do the following (code from gns-ank):

    def cm2inch(*tupl):
        inch = 2.54
        if isinstance(tupl[0], tuple):
            return tuple(i/inch for i in tupl[0])
        else:
            return tuple(i/inch for i in tupl)
    

    Then you can use:

    plt.figure(figsize=cm2inch(21, 29.7))
    

提交回复
热议问题