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