@@ -202,25 +202,34 @@ def use(self, key, value):
202
202
203
203
def scatter_matrix (frame , alpha = 0.5 , figsize = None , ax = None , grid = False ,
204
204
diagonal = 'hist' , marker = '.' , density_kwds = None ,
205
- hist_kwds = None , ** kwds ):
205
+ hist_kwds = None , range_padding = 0.05 , ** kwds ):
206
206
"""
207
207
Draw a matrix of scatter plots.
208
208
209
209
Parameters
210
210
----------
211
211
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
217
221
either Kernel Density Estimation or Histogram
218
222
plot in the diagonal
219
- marker : Matplotlib marker type, default '.'
223
+ marker : str, optional
224
+ Matplotlib marker type, default '.'
220
225
hist_kwds : other plotting keyword arguments
221
226
To be passed to hist function
222
227
density_kwds : other plotting keyword arguments
223
228
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
224
233
kwds : other plotting keyword arguments
225
234
To be passed to scatter function
226
235
@@ -250,6 +259,13 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
250
259
# workaround because `c='b'` is hardcoded in matplotlibs scatter method
251
260
kwds .setdefault ('c' , plt .rcParams ['patch.facecolor' ])
252
261
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
+
253
269
for i , a in zip (lrange (n ), df .columns ):
254
270
for j , b in zip (lrange (n ), df .columns ):
255
271
ax = axes [i , j ]
@@ -260,18 +276,25 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
260
276
# Deal with the diagonal by drawing a histogram there.
261
277
if diagonal == 'hist' :
262
278
ax .hist (values , ** hist_kwds )
279
+
263
280
elif diagonal in ('kde' , 'density' ):
264
281
from scipy .stats import gaussian_kde
265
282
y = values
266
283
gkde = gaussian_kde (y )
267
284
ind = np .linspace (y .min (), y .max (), 1000 )
268
285
ax .plot (ind , gkde .evaluate (ind ), ** density_kwds )
286
+
287
+ ax .set_xlim (boundaries_list [i ])
288
+
269
289
else :
270
290
common = (mask [a ] & mask [b ]).values
271
291
272
292
ax .scatter (df [b ][common ], df [a ][common ],
273
293
marker = marker , alpha = alpha , ** kwds )
274
294
295
+ ax .set_xlim (boundaries_list [j ])
296
+ ax .set_ylim (boundaries_list [i ])
297
+
275
298
ax .set_xlabel ('' )
276
299
ax .set_ylabel ('' )
277
300
0 commit comments