|
1 | 1 | from __future__ import division, generators |
2 | 2 |
|
3 | | -import math, sys |
| 3 | +import math, sys, random |
4 | 4 |
|
5 | 5 | from numerix import MLab, absolute, arange, array, asarray, ones, transpose, \ |
6 | 6 | log, log10, Float, ravel |
|
11 | 11 | from cbook import iterable, is_string_like, flatten, enumerate, True, False,\ |
12 | 12 | allequal |
13 | 13 | from collections import RegularPolyCollection, PolyCollection |
14 | | -from colors import colorConverter, normalize, Colormap |
| 14 | +from colors import colorConverter, normalize, Colormap, LinearSegmentedColormap |
15 | 15 | import cm |
16 | 16 | from cm import ColormapJet, Grayscale |
17 | 17 | import _image |
@@ -2419,6 +2419,7 @@ def set_yticks(self, ticks): |
2419 | 2419 | 'Set the y ticks with list of ticks' |
2420 | 2420 | return self.yaxis.set_ticks(ticks) |
2421 | 2421 |
|
| 2422 | + |
2422 | 2423 | def specgram(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
2423 | 2424 | window=mlab.window_hanning, noverlap=128, |
2424 | 2425 | cmap = None, xextent=None): |
@@ -2466,6 +2467,37 @@ def specgram(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none, |
2466 | 2467 |
|
2467 | 2468 | return Pxx, freqs, bins, im |
2468 | 2469 |
|
| 2470 | + def spy(self, Z, marker='s', markersize=10, **kwargs): |
| 2471 | + """ |
| 2472 | + SPY(Z, **kwrags) plots the sparsity pattern of the matrix S |
| 2473 | + using plot markers. |
| 2474 | +
|
| 2475 | + kwargs give the marker properties - see help(plot) for more |
| 2476 | + information on marker properties |
| 2477 | +
|
| 2478 | + The line handles are returned |
| 2479 | + """ |
| 2480 | + x,y,z = mlab.get_xyz_where(Z, Z>0) |
| 2481 | + return self.plot(x+0.5,y+0.5, linestyle='None', |
| 2482 | + marker=marker,markersize=markersize, **kwargs) |
| 2483 | + |
| 2484 | + def spy2(self, Z): |
| 2485 | + """ |
| 2486 | +SPY2(Z) plots the sparsity pattern of the matrix S as an image |
| 2487 | +
|
| 2488 | +The image instance is returned |
| 2489 | + """ |
| 2490 | + |
| 2491 | + #binary colormap min white, max black |
| 2492 | + cmapdata = { |
| 2493 | + 'red' : ((0., 1., 1.), (1., 0., 0.)), |
| 2494 | + 'green': ((0., 1., 1.), (1., 0., 0.)), |
| 2495 | + 'blue' : ((0., 1., 1.), (1., 0., 0.)) |
| 2496 | + } |
| 2497 | + binary = LinearSegmentedColormap('binary', cmapdata, 2) |
| 2498 | + Z = where(Z>0,1.,0.) |
| 2499 | + return self.imshow(transpose(Z), interpolation='nearest', cmap=binary) |
| 2500 | + |
2469 | 2501 | def table(self, |
2470 | 2502 | cellText=None, cellColours=None, |
2471 | 2503 | cellLoc='right', colWidths=None, |
|
0 commit comments