pythonmatplotlibjupyter-notebook

how to set matplotlib figsize using axes and subplots


Hello I have a very basic plot with matplotlib but I want to be able to set the figure size I am confused about how to do this when not using multiple subplots. I am confused about the relationship between the figsize and subplots see code below:

plt.figure(figsize=(10,10))    

y = np.arange(1,6,1)
y1 = y**2
y2 = y**3
y3 = y**4
x = np.arange(1,101,20)

fig, ax = plt.subplots()
ax.plot(x,y1)
ax.plot(x,y2)
ax.plot(x,y3)

Solution

  • Just put in 1 row and 1 column of subplots and that will give you one plot.

    fig, ax = plt.subplots(1, 1, figsize=(8,8))
    
    y = np.arange(1,6,1)
    y1 = y**2
    y2 = y**3
    y3 = y**4
    x = np.arange(1,101,20)
    
    fig, ax = plt.subplots()
    ax.plot(x,y1)
    ax.plot(x,y2)
    ax.plot(x,y3)
    
    fig.savefig('eightbyeight.png', dpi = 300)