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

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

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

19条回答
  •  -上瘾入骨i
    2020-11-21 06:46

    Generalizing and simplifying psihodelia's answer. If you want to change the current size of the figure by a factor sizefactor

    import matplotlib.pyplot as plt
    
    # here goes your code
    
    fig_size = plt.gcf().get_size_inches() #Get current size
    sizefactor = 0.8 #Set a zoom factor
    # Modify the current size by the factor
    plt.gcf().set_size_inches(sizefactor * fig_size) 
    

    After changing the current size, it might occur that you have to fine tune the subplot layout. You can do that in the figure window GUI, or by means of the command subplots_adjust

    For example,

    plt.subplots_adjust(left=0.16, bottom=0.19, top=0.82)
    

提交回复
热议问题