# Python教程-如何在Matplotlib中更改绘图大小

``````# first, import the matplotlib library
import matplotlib.pyplot as plot

# The values on x-axis
x_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# The values on y-axis
y_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

# Now, name the x and y axis
plot.xlabel('X - AXIS')
plot.ylabel('Y - AXIS')

#Then, plot the line plot with its default size
print ("The plot is plotted in its default size: ")
plot.plot(x_axis, y_axis)
plot.show()

# Now, plot the line plot after changing the size of its width and height
K = plot.figure()
K.set_figwidth(5)
K.set_figheight(2)

print ("The plot is plotted after changing its size: ")
plot.plot(x_axis, y_axis)
plot.show()  ``````

``````The plot is plotted in its default size:
How to Change Plot Size in Matplotlib

The plot is plotted after changing its size:
How to Change Plot Size in Matplotlib``````

figsize()函数接受两个参数，即宽度和高度，单位为英寸。默认情况下，宽度=6.4英寸，高度=4.8英寸。

``````# First, import the matplotlib library
import matplotlib.pyplot as plot

# The values on x-axis
x_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# The values on y-axis
y_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

#Then, plot the line plot with its default size
print ("The plot is plotted in its default size: ")
plot.plot(x_axis, y_axis)
plot.show()

# Now, plot the line plot after changing the size of figure to 3 X 3
plot.figure(figsize = (3, 3))
print ("The plot is plotted after changing its size: ")
plot.plot(x_axis, y_axis)
plot.show()  ``````

``````The plot is plotted in its default size:
How to Change Plot Size in Matplotlib

The plot is plotted after changing its size:
How to Change Plot Size in Matplotlib``````

``````# First, import the matplotlib library
import matplotlib.pyplot as plot

# The values on x-axis
x_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# The values on y-axis
y_axis = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

# now, name the x axis
plot.xlabel('X - AXIS')
# name the y axis
plot.ylabel('Y - AXIS')

#Then, plot the line plot with its default size
print ("The plot is plotted in its default size: ")
plot.plot(x_axis, y_axis)
plot.show()

# Now, change the rc parameters and plot the line plot after changing the size.
plot.rcParams['figure.figsize'] = [3, 3]

print ("The plot is plotted after changing its size: ")
plot.plot(x_axis, y_axis)
plot.show()

plot.scatter(x_axis, y_axis)
plot.show()  ``````

``````The plot is plotted in its default size:
How to Change Plot Size in Matplotlib

The plot is plotted after changing its size:
How to Change Plot Size in Matplotlib
How to Change Plot Size in Matplotlib``````