@@ -1039,115 +1039,119 @@ def subplot(*args, **kwargs):
1039
1039
1040
1040
1041
1041
def subplots (nrows = 1 , ncols = 1 , sharex = False , sharey = False , squeeze = True ,
1042
- subplot_kw = None , gridspec_kw = None , ** fig_kw ):
1042
+ subplot_kw = None , gridspec_kw = None , ** fig_kw ):
1043
1043
"""
1044
- Create a figure with a set of subplots already made.
1044
+ Create a figure and a set of subplots
1045
1045
1046
1046
This utility wrapper makes it convenient to create common layouts of
1047
1047
subplots, including the enclosing figure object, in a single call.
1048
1048
1049
- Keyword arguments:
1050
-
1051
- *nrows* : int
1052
- Number of rows of the subplot grid. Defaults to 1.
1053
-
1054
- *ncols* : int
1055
- Number of columns of the subplot grid. Defaults to 1.
1056
-
1057
- *sharex* : string or bool
1058
- If *True*, the X axis will be shared amongst all subplots. If
1059
- *True* and you have multiple rows, the x tick labels on all but
1060
- the last row of plots will have visible set to *False*
1061
- If a string must be one of "row", "col", "all", or "none".
1062
- "all" has the same effect as *True*, "none" has the same effect
1063
- as *False*.
1064
- If "row", each subplot row will share a X axis.
1065
- If "col", each subplot column will share a X axis and the x tick
1066
- labels on all but the last row will have visible set to *False*.
1067
-
1068
- *sharey* : string or bool
1069
- If *True*, the Y axis will be shared amongst all subplots. If
1070
- *True* and you have multiple columns, the y tick labels on all but
1071
- the first column of plots will have visible set to *False*
1072
- If a string must be one of "row", "col", "all", or "none".
1073
- "all" has the same effect as *True*, "none" has the same effect
1074
- as *False*.
1075
- If "row", each subplot row will share a Y axis and the y tick
1076
- labels on all but the first column will have visible set to *False*.
1077
- If "col", each subplot column will share a Y axis.
1078
-
1079
- *squeeze* : bool
1080
- If *True*, extra dimensions are squeezed out from the
1081
- returned axis object:
1082
-
1083
- - if only one subplot is constructed (nrows=ncols=1), the
1084
- resulting single Axis object is returned as a scalar.
1085
-
1086
- - for Nx1 or 1xN subplots, the returned object is a 1-d numpy
1087
- object array of Axis objects are returned as numpy 1-d
1088
- arrays.
1089
-
1090
- - for NxM subplots with N>1 and M>1 are returned as a 2d
1091
- array.
1092
-
1093
- If *False*, no squeezing at all is done: the returned axis
1094
- object is always a 2-d array containing Axis instances, even if it
1095
- ends up being 1x1.
1096
-
1097
- *subplot_kw* : dict
1049
+ Parameters
1050
+ ----------
1051
+ nrows, ncols : int, optional, default: 1
1052
+ Number of rows/columns of the subplot grid.
1053
+
1054
+ sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
1055
+ Controls sharing of properties among x (`sharex`) or y (`sharey`)
1056
+ axes:
1057
+
1058
+ - True or 'all': x- or y-axis will be shared among all
1059
+ subplots.
1060
+ - False or 'none': each subplot x- or y-axis will be
1061
+ independent.
1062
+ - 'row': each subplot row will share an x- or y-axis.
1063
+ - 'col': each subplot column will share an x- or y-axis.
1064
+
1065
+ When subplots have a shared x-axis along a column, only the x tick
1066
+ labels of the bottom subplot are visible. Similarly, when subplots
1067
+ have a shared y-axis along a row, only the y tick labels of the first
1068
+ column subplot are visible.
1069
+
1070
+ squeeze : bool, optional, default: True
1071
+ - If True, extra dimensions are squeezed out from the returned Axes
1072
+ object:
1073
+
1074
+ - if only one subplot is constructed (nrows=ncols=1), the
1075
+ resulting single Axes object is returned as a scalar.
1076
+ - for Nx1 or 1xN subplots, the returned object is a 1D numpy
1077
+ object array of Axes objects are returned as numpy 1D arrays.
1078
+ - for NxM, subplots with N>1 and M>1 are returned as a 2D arrays.
1079
+
1080
+ - If False, no squeezing at all is done: the returned Axes object is
1081
+ always a 2D array containing Axes instances, even if it ends up
1082
+ being 1x1.
1083
+
1084
+ subplot_kw : dict, optional
1098
1085
Dict with keywords passed to the
1099
- :meth:`~matplotlib.figure.Figure.add_subplot` call used to
1100
- create each subplots .
1086
+ :meth:`~matplotlib.figure.Figure.add_subplot` call used to create each
1087
+ subplot .
1101
1088
1102
- * gridspec_kw* : dict
1089
+ gridspec_kw : dict, optional
1103
1090
Dict with keywords passed to the
1104
- :class:`~matplotlib.gridspec.GridSpec` constructor used to create
1105
- the grid the subplots are placed on.
1091
+ :class:`~matplotlib.gridspec.GridSpec` constructor used to create the
1092
+ grid the subplots are placed on.
1106
1093
1107
- * fig_kw* : dict
1094
+ fig_kw : dict, optional
1108
1095
Dict with keywords passed to the :func:`figure` call. Note that all
1109
1096
keywords not recognized above will be automatically included here.
1110
1097
1111
- Returns:
1112
-
1113
- fig, ax : tuple
1098
+ Returns
1099
+ -------
1100
+ fig : :class:`matplotlib.figure.Figure` object
1114
1101
1115
- - *fig* is the :class:`matplotlib.figure.Figure` object
1102
+ ax : Axes object or array of Axes objects.
1116
1103
1117
- - *ax* can be either a single axis object or an array of axis
1118
- objects if more than one subplot was created. The dimensions
1119
- of the resulting array can be controlled with the squeeze
1104
+ ax can be either a single :class:`matplotlib.axes.Axes` object or an
1105
+ array of Axes objects if more than one subplot was created. The
1106
+ dimensions of the resulting array can be controlled with the squeeze
1120
1107
keyword, see above.
1121
1108
1122
- Examples::
1109
+ Examples
1110
+ --------
1111
+ First create some toy data:
1112
+
1113
+ >>> x = np.linspace(0, 2*np.pi, 400)
1114
+ >>> y = np.sin(x**2)
1123
1115
1124
- x = np.linspace(0, 2*np.pi, 400)
1125
- y = np.sin(x**2)
1116
+ Creates just a figure and only one subplot
1126
1117
1127
- # Just a figure and one subplot
1128
- f, ax = plt.subplots()
1129
- ax.plot(x, y)
1130
- ax.set_title('Simple plot')
1118
+ >>> fig, ax = plt.subplots()
1119
+ >>> ax.plot(x, y)
1120
+ >>> ax.set_title('Simple plot')
1131
1121
1132
- # Two subplots, unpack the output array immediately
1133
- f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
1134
- ax1.plot(x, y)
1135
- ax1.set_title('Sharing Y axis')
1136
- ax2.scatter(x, y)
1122
+ Creates two subplots and unpacks the output array immediately
1137
1123
1138
- # Four polar axes
1139
- plt.subplots(2, 2, subplot_kw=dict(polar=True))
1124
+ >>> f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
1125
+ >>> ax1.plot(x, y)
1126
+ >>> ax1.set_title('Sharing Y axis')
1127
+ >>> ax2.scatter(x, y)
1140
1128
1141
- # Share a X axis with each column of subplots
1142
- plt.subplots(2, 2, sharex='col')
1129
+ Creates four polar axes, and accesses them through the returned array
1143
1130
1144
- # Share a Y axis with each row of subplots
1145
- plt.subplots(2, 2, sharey='row')
1131
+ >>> fig, axes = plt.subplots(2, 2, subplot_kw=dict(polar=True))
1132
+ >>> axes[0, 0].plot(x, y)
1133
+ >>> axes[1, 1].scatter(x, y)
1146
1134
1147
- # Share a X and Y axis with all subplots
1148
- plt.subplots(2, 2, sharex='all', sharey='all')
1149
- # same as
1150
- plt.subplots(2, 2, sharex=True, sharey=True)
1135
+ Share a X axis with each column of subplots
1136
+
1137
+ >>> plt.subplots(2, 2, sharex='col')
1138
+
1139
+ Share a Y axis with each row of subplots
1140
+
1141
+ >>> plt.subplots(2, 2, sharey='row')
1142
+
1143
+ Share both X and Y axes with all subplots
1144
+
1145
+ >>> plt.subplots(2, 2, sharex='all', sharey='all')
1146
+
1147
+ Note that this is the same as
1148
+
1149
+ >>> plt.subplots(2, 2, sharex=True, sharey=True)
1150
+
1151
+ See Also
1152
+ --------
1153
+ figure
1154
+ subplot
1151
1155
"""
1152
1156
# for backwards compatibility
1153
1157
if isinstance (sharex , bool ):
0 commit comments