@@ -202,25 +202,34 @@ def use(self, key, value):
202202
203203def scatter_matrix (frame , alpha = 0.5 , figsize = None , ax = None , grid = False ,
204204 diagonal = 'hist' , marker = '.' , density_kwds = None ,
205- hist_kwds = None , ** kwds ):
205+ hist_kwds = None , range_padding = 0.05 , ** kwds ):
206206 """
207207 Draw a matrix of scatter plots.
208208
209209 Parameters
210210 ----------
211211 frame : DataFrame
212- alpha : amount of transparency applied
213- figsize : a tuple (width, height) in inches
214- ax : Matplotlib axis object
215- grid : setting this to True will show the grid
216- diagonal : pick between 'kde' and 'hist' for
212+ alpha : float, optional
213+ amount of transparency applied
214+ figsize : (float,float), optional
215+ a tuple (width, height) in inches
216+ ax : Matplotlib axis object, optional
217+ grid : bool, optional
218+ setting this to True will show the grid
219+ diagonal : {'hist', 'kde'}
220+ pick between 'kde' and 'hist' for
217221 either Kernel Density Estimation or Histogram
218222 plot in the diagonal
219- marker : Matplotlib marker type, default '.'
223+ marker : str, optional
224+ Matplotlib marker type, default '.'
220225 hist_kwds : other plotting keyword arguments
221226 To be passed to hist function
222227 density_kwds : other plotting keyword arguments
223228 To be passed to kernel density estimate plot
229+ range_padding : float, optional
230+ relative extension of axis range in x and y
231+ with respect to (x_max - x_min) or (y_max - y_min),
232+ default 0.05
224233 kwds : other plotting keyword arguments
225234 To be passed to scatter function
226235
@@ -250,6 +259,13 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
250259 # workaround because `c='b'` is hardcoded in matplotlibs scatter method
251260 kwds .setdefault ('c' , plt .rcParams ['patch.facecolor' ])
252261
262+ boundaries_list = []
263+ for a in df .columns :
264+ values = df [a ].values [mask [a ].values ]
265+ rmin_ , rmax_ = np .min (values ), np .max (values )
266+ rdelta_ext = (rmax_ - rmin_ ) * range_padding / 2.
267+ boundaries_list .append ((rmin_ - rdelta_ext , rmax_ + rdelta_ext ))
268+
253269 for i , a in zip (lrange (n ), df .columns ):
254270 for j , b in zip (lrange (n ), df .columns ):
255271 ax = axes [i , j ]
@@ -260,18 +276,25 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
260276 # Deal with the diagonal by drawing a histogram there.
261277 if diagonal == 'hist' :
262278 ax .hist (values , ** hist_kwds )
279+
263280 elif diagonal in ('kde' , 'density' ):
264281 from scipy .stats import gaussian_kde
265282 y = values
266283 gkde = gaussian_kde (y )
267284 ind = np .linspace (y .min (), y .max (), 1000 )
268285 ax .plot (ind , gkde .evaluate (ind ), ** density_kwds )
286+
287+ ax .set_xlim (boundaries_list [i ])
288+
269289 else :
270290 common = (mask [a ] & mask [b ]).values
271291
272292 ax .scatter (df [b ][common ], df [a ][common ],
273293 marker = marker , alpha = alpha , ** kwds )
274294
295+ ax .set_xlim (boundaries_list [j ])
296+ ax .set_ylim (boundaries_list [i ])
297+
275298 ax .set_xlabel ('' )
276299 ax .set_ylabel ('' )
277300
0 commit comments