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

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

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

19条回答
  •  一生所求
    2020-11-21 06:27

    USING plt.rcParams

    There is also this workaround in case you want to change the size without using the figure environment. So in case you are using plt.plot() for example, you can set a tuple with width and height.

    import matplotlib.pyplot as plt
    plt.rcParams["figure.figsize"] = (20,3)
    

    This is very useful when you plot inline (e.g. with IPython Notebook). As @asamaier noticed is preferable to not put this statement in the same cell of the imports statements.

    Conversion to cm

    The figsize tuple accepts inches so if you want to set it in centimetres you have to divide them by 2.54 have a look to this question.

提交回复
热议问题