How do I change the figure size with subplots?

后端 未结 2 1729
刺人心
刺人心 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.

    0 讨论(0)
  • 2020-11-28 18:16

    If you already have the figure object use:

    f.set_figheight(15)
    f.set_figwidth(15)
    

    But if you use the .subplots() command (as in the examples you're showing) to create a new figure you can also use:

    f, axs = plt.subplots(2,2,figsize=(15,15))
    
    0 讨论(0)
提交回复
热议问题