8000 New version of colorbar, plus small bugfixes. · anntzer/matplotlib@4d1107c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d1107c

Browse files
committed
New version of colorbar, plus small bugfixes.
svn path=/trunk/matplotlib/; revision=2390
1 parent 5d523b4 commit 4d1107c

17 files changed

+670
-80
lines changed

API_CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Colorbar: completely new version and api; see docstring.
2+
13
Contourf: "extend" kwarg replaces "clip_ends"; see docstring.
24
Masked array support added to pcolormesh.
35

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2006-05-14 New colorbar; old one is renamed to colorbar_classic.
2+
New colorbar code is in colorbar.py, with wrappers in
3+
figure.py and pylab.py.
4+
Fixed aspect-handling bug reported by Michael Mossey.
5+
Made backend_bases.draw_quad_mesh() run.- EF
6+
17
2006-05-08 Changed handling of end ranges in contourf: replaced
28
"clip-ends" kwarg with "extend". See docstring for
39
details. -EF

examples/backend_driver.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from __future__ import division
8-
import os, time
8+
import os, time, sys
99
files = (
1010
'alignment_test.py',
1111
'arctest.py',
@@ -19,7 +19,7 @@
1919
'custom_ticker1.py',
2020
'customize_rc.py',
2121
'date_demo1.py',
22-
'date_demo2.py',
22+
'date_demo2.py',
2323
'figimage_demo.py',
2424
'figlegend_demo.py',
2525
'figtext.py',
@@ -40,7 +40,7 @@
4040
'log_demo.py',
4141
'log_test.py',
4242
'major_minor_demo1.py',
43-
'major_minor_demo2.py',
43+
'major_minor_demo2.py',
4444
'mathtext_demo.py',
4545
'mri_with_eeg.py',
4646
'multiple_figs_demo.py',
@@ -57,12 +57,12 @@
5757
'specgram_demo.py',
5858
'stock_demo.py',
5959
'subplot_demo.py',
60-
# 'set_and_get.py',
60+
# 'set_and_get.py',
6161
'table_demo.py',
6262
'text_handles.py',
6363
'text_rotation.py',
6464
'text_themes.py',
65-
# 'tex_demo.py',
65+
# 'tex_demo.py',
6666
'two_scales.py',
6767
'unicode_demo.py',
6868
'vline_demo.py',
@@ -73,7 +73,7 @@
7373
#tests known to fail on python22 (require datetime)
7474
fail22 = (
7575
'date_demo1.py',
76-
'date_demo2.py',
76+
'date_demo2.py',
7777
'finance_demo.py',
7878
)
7979

@@ -87,12 +87,12 @@
8787
def drive(backend, python='python2.4'):
8888

8989
exclude = failbackend.get(backend, [])
90-
90+
9191
for fname in files:
9292
if fname in exclude:
9393
print '\tSkipping %s, known to fail on backend: %s'%backend
9494
continue
95-
95+
9696
if python=='python2.2' and fname in fail22:
9797
print '\tSkipping %s, known to fail on python2.2'%fname
9898
continue
@@ -130,9 +130,13 @@ def drive(backend, python='python2.4'):
130130
# backends = ['Agg', 'Cairo', 'GDK', 'PS', 'SVG', 'Template']
131131
#backends = ['Agg', 'PS', 'SVG', 'Template']
132132
# backends = [ 'GTK', 'WX', 'TkAgg']
133-
backends = ['Agg', 'PS', 'SVG', 'Template']
133+
default_backends = ['Agg', 'PS', 'SVG', 'Template']
134134
#backends = ['Agg']
135135
python = 'python2.4'
136+
if sys.argv[1:]:
137+
backends = [b for b in sys.argv[1:] if b in default_backends]
138+
else:
139+
backends = default_backends
136140
for backend in backends:
137141
print 'testing %s' % backend
138142
t0 = time.time()

examples/contour_demo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@
7272
fmt='%1.1f',
7373
fontsize=14)
7474

75-
colorbar(CS) # make a colorbar for the contour lines
75+
# make a colorbar for the contour lines
76+
CB = colorbar(CS, shrink=0.8, extend='both')
77+
7678
title('Lines with colorbar')
7779
hot() # Now change the colormap for the contour lines and colorbar
7880
flag()
7981

8082
# We can still add a colorbar for the image, too.
81-
colorbar(im, orientation='horizontal')
83+
CBI = colorbar(im, orientation='horizontal', shrink=0.8)
8284
# We could manipulate the colorbar axes sizes for better
8385
# appearance, but we'll leave that for a later demo.
8486

examples/contourf_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
ylabel('sentence length anomaly')
5656

5757
# Make a colorbar for the ContourSet returned by the contourf call.
58-
ax_cbar = colorbar(CS, tickfmt='%1.2f')
59-
ax_cbar.set_ylabel('verbosity coefficient')
58+
cbar = colorbar(CS)
59+
cbar.ax.set_ylabel('verbosity coefficient')
6060

6161
figure()
6262

examples/image_masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
norm = colors.normalize(vmin = -1.0, vmax = 1.0, clip = False),
3737
origin='lower', extent=[-3,3,-3,3])
3838
title('Green=low, Red=high, Blue=bad')
39-
# colorbar(im) # colorbar does not yet show the under and over colors.
39+
colorbar(im, extend='both')
4040
show()
4141

examples/poormans_contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
im = imshow(Z, cmap=cmap, interpolation='bilinear')
2424
axis('off')
25-
colorbar(tickfmt='%1.2f')
25+
colorbar()
2626
#savefig('test')
2727
show()
2828

lib/matplotlib/axes.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def set_anchor(self, anchor):
618618
"""
619619
ACCEPTS: ['C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W']
620620
"""
621-
if anchor in PBox.coefs.keys():
621+
if anchor in PBox.coefs.keys() or len(anchor) == 2:
622622
self._anchor = anchor
623623
else:
624624
raise ValueError('argument must be among %s' %
@@ -667,10 +667,14 @@ def apply_aspect(self, data_ratio = None):
667667
dL = self.dataLim
668668
xr = dL.width()
669669
yr = dL.height()
670+
xsize = min(xsize, 1.1*xr)
671+
ysize = min(ysize, 1.1*yr)
670672
xmarg = xsize - xr
671673
ymarg = ysize - yr
672674
Ysize = data_ratio * xsize
673675
Xsize = ysize / data_ratio
676+
Xmarg = Xsize - xr
677+
Ymarg = Ysize - xr
674678
# If it is very nearly correct, don't do any more;
675679
# we are probably just panning.
676680
if abs(xsize-Xsize) < 0.001*xsize or abs(ysize-Ysize) < 0.001*ysize:
@@ -686,8 +690,7 @@ def apply_aspect(self, data_ratio = None):
686690
if changex:
687691
adjust_y = False
688692
else:
689-
adjust_y = changey or (Xsize < min(xsize, xr))
690-
adjust_y = adjust_y or (A*ymarg > xmarg)
693+
adjust_y = changey or (Ymarg > xmarg)
691694
if adjust_y:
692695
dy = Ysize - ysize
693696
if ymarg < 0.01 * dy:
@@ -945,7 +948,6 @@ def autoscale_view(self, tight=False):
945948
self.set_xlim(locator.autoscale())
946949
locator = self.yaxis.get_major_locator()
947950
self.set_ylim(locator.autoscale())
948-
949951
#### Drawing
950952

951953
def draw(self, renderer=None, inframe=False):
@@ -997,6 +999,7 @@ def draw(self, renderer=None, inframe=False):
997999
artists.extend(self.patches)
9981000
artists.extend(self.lines)
9991001
artists.extend(self.texts)
1002+
artists.extend(self.artists)
10001003

10011004
# keep track of i to guarantee stable sort for python 2.2
10021005
dsu = [ (a.zorder, i, a) for i, a in enumerate(artists)
@@ -1008,9 +1011,6 @@ def draw(self, renderer=None, inframe=False):
10081011

10091012
self.title.draw(renderer)
10101013
if 0: bbox_artist(self.title, renderer)
1011-
# optional artists
1012-
for a in self.artists:
1013-
a.draw(renderer)
10141014

10151015
if not self._axisbelow:
10161016
if self.axison and not inframe:
@@ -1027,7 +1027,6 @@ def draw(self, renderer=None, inframe=False):
10271027
self.transData.thaw() # release the lazy objects
10281028
self.transAxes.thaw() # release the lazy objects
10291029
renderer.close_group('axes')
1030-
10311030
self._cachedRenderer = renderer
10321031

10331032
def draw_artist(self, a):
@@ -3068,8 +3067,10 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
30683067
collection.set_cmap(cmap)
30693068
collection.set_norm(norm)
30703069

3071-
if norm is None:
3070+
if vmin is not None or vmax is not None:
30723071
collection.set_clim(vmin, vmax)
3072+
else:
3073+
collection.autoscale()
30733074

30743075
minx = amin(x)
30753076
maxx = amax(x)
@@ -3411,11 +3412,15 @@ def imshow(self, X,
34113412
im = AxesImage(self, cmap, norm, interpolation, origin, extent,
34123413
filternorm=filternorm,
34133414
filterrad=filterrad)
3414-
if norm is None and shape is None:
3415-
im.set_clim(vmin, vmax)
34163415

34173416
im.set_data(X)
34183417
im.set_alpha(alpha)
3418+
#if norm is None and shape is None:
3419+
# im.set_clim(vmin, vmax)
3420+
if vmin is not None or vmax is not None:
3421+
im.set_clim(vmin, vmax)
3422+
else:
3423+
im.autoscale()
34193424

34203425
xmin, xmax, ymin, ymax = im.get_extent()
34213426

@@ -3570,8 +3575,10 @@ def pcolor(self, *args, **kwargs):
35703575
if cmap is not None: assert(isinstance(cmap, Colormap))
35713576
collection.set_cmap(cmap)
35723577
collection.set_norm(norm)
3573-
collection.set_clim(vmin, vmax)
3574-
3578+
if vmin is not None or vmax is not None:
3579+
collection.set_clim(vmin, vmax)
3580+
else:
3581+
collection.autoscale()
35753582
self.grid(False)
35763583

35773584
x = X.compressed()
@@ -3677,7 +3684,10 @@ def pcolormesh(self, *args, **kwargs):
36773684
if cmap is not None: assert(isinstance(cmap, Colormap))
36783685
collection.set_cmap(cmap)
36793686
collection.set_norm(norm)
3680-
collection.set_clim(vmin, vmax)
3687+
if vmin is not None or vmax is not None:
3688+
collection.set_clim(vmin, vmax)
3689+
else:
3690+
collection.autoscale()
36813691

36823692
self.grid(False)
36833693

@@ -4082,7 +4092,7 @@ def spy(self, Z, marker='s', markersize=10, **kwargs):
40824092
x = c.row
40834093
y = c.col
40844094
z = c.data
4085-
else:
4095+
else:
40864096
x,y,z = matplotlib.mlab.get_xyz_where(Z, Z>0)
40874097
return self.plot(x+0.5,y+0.5, linestyle='None',
40884098
marker=marker,markersize=markersize, **kwargs)

lib/matplotlib/axis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ def _get_tick1line(self, loc):
275275
marker = self._xtickmarkers[0],
276276
markersize=self._size,
277277
)
278-
279278
l.set_transform( blend_xy_sep_transform( self.axes.transData,
280279
self.axes.transAxes) )
281280
self._set_artist_props(l)

lib/matplotlib/cm.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ def to_rgba(self, x, alpha=1.0):
5959

6060
def set_array(self, A):
6161
'Set the image array from numeric/numarray A'
62-
self._A = A.astype(nx.Float32)
62+
from numerix import typecode, typecodes
63+
if typecode(A) in typecodes['Float']:
64+
self._A = A.astype(nx.Float32)
65+
else:
66+
self._A = A.astype(nx.Int16)
6367

6468
def get_array(self):
6569
'Return the array'
6670
return self._A
6771

68-
def set_clim(self, vmin=None, vmax=None, force=True):
72+
def set_clim(self, vmin=None, vmax=None):
6973
'set the norm limits for image scaling'
70-
if force or not self.norm.scaled():
71-
self.norm.vmin = vmin
72-
self.norm.vmax = vmax
73-
if self.colorbar is not None:
74-
im, ax = self.colorbar
75-
ax.set_ylim((vmin, vmax)) ############# FIXME
76-
self.changed()
74+
if vmin is not None: self.norm.vmin = vmin
75+
if vmax is not None: self.norm.vmax = vmax
76+
self.changed()
7777

7878
def set_cmap(self, cmap):
7979
'set the colormap for luminance data'

0 commit comments

Comments
 (0)
0