How do I change the figure size with subplots?

后端 未结 2 1748
刺人心
刺人心 2020-11-28 17:31

I came across this example in the Matplotlib website. I was wondering if it was possible to increase the figure size.

I tried with

f.figsize(15,15)
<         


        
2条回答
  •  佛祖请我去吃肉
    2020-11-28 18:12

    Alternatively, create a figure() object using the figsize argument and then use add_subplot to add your subplots. E.g.

    import matplotlib.pyplot as plt
    import numpy as np
    
    f = plt.figure(figsize=(10,3))
    ax = f.add_subplot(121)
    ax2 = f.add_subplot(122)
    x = np.linspace(0,4,1000)
    ax.plot(x, np.sin(x))
    ax2.plot(x, np.cos(x), 'r:')
    

    Benefits of this method are that the syntax is closer to calls of subplot() instead of subplots(). E.g. subplots doesn't seem to support using a GridSpec for controlling the spacing of the subplots, but both subplot() and add_subplot() do.

提交回复
热议问题