matplotlib.pyplot.subplot

来源:互联网 发布:ubuntu tty1 登录 编辑:程序博客网 时间:2024/06/10 23:11
matplotlib.pyplot.subplot(*args, **kwargs)

Return a subplot axes positioned by the given grid definition.

Typical call signature:

subplot(nrows, ncols, plot_number)

Where nrows and ncols are used to notionally split the figure into nrows * ncols sub-axes, and plot_number is used to identify the particular subplot that this function is to create within the notional grid. plot_number starts at 1, increments across rows first and has a maximum of nrows * ncols.

In the case when nrows, ncols and plot_number are all less than 10, a convenience exists, such that the a 3 digit number can be given instead, where the hundreds represent nrows, the tens represent ncols and the units represent plot_number. For instance:

subplot(211)

produces a subaxes in a figure which represents the top plot (i.e. the first) in a 2 row by 1 column notional grid (no grid actually exists, but conceptually this is how the returned subplot has been positioned).

Note
Creating a subplot will delete any pre-existing subplot that overlaps with it beyond sharing a boundary:

import matplotlib.pyplot as plt# plot a line, implicitly creating a subplot(111)plt.plot([1,2,3])# now create a subplot which represents the top plot of a grid# with 2 rows and 1 column. Since this subplot will overlap the# first, the plot (and its axes) previously created, will be removedplt.subplot(211)plt.plot(range(12))# creates 2nd subplot with yellow backgroundplt.subplot(212, facecolor='y') 
0 0
原创粉丝点击