1
## Automatically adapted for scipy Oct 31, 2005 by
3
# Copyright (c) 1996, 1997, The Regents of the University of California.
4
# All rights reserved. See Legal.htm for full text and disclaimer.
6
# ed williams' colorbar stuff
8
from numpy.core.umath import *
13
def nice_levels (z, n = 8) :
14
"""nice_levels(z, n = 8) finds approximately n "nice values"
15
between min(z) and max(z) for axis labels. n defaults to eight.
17
zmax = max (ravel (z))
18
zmin = min (ravel (z))
19
finest = abs (zmax - zmin) / float (n)
20
# blows up on zmin=zmax
21
unit = 10. ** floor (log10 (finest))
22
finest = finest / unit
30
cmin = unit * ceil (zmin / unit)
31
if (abs (cmin - zmin) < 0.01 * unit) :
33
cmax = unit * floor (zmax / unit)
34
if (abs (cmax - zmax) < 0.01 * unit) :
36
n = int ( ( (cmax - cmin) / unit + 0.5) + 1)
37
levs = span (cmin, cmax, n)
38
list = nonzero (less (abs (levs), 0.1 * unit))
40
array_set (levs, list, 0.0)
43
def color_bar (minz, maxz, split = 0, ncol = None, ymax=0.85, ymin=0.44, xmin0=0.62, xmax0=0.64, zlabel=None, fontsize=16, font='helvetica', color='black') :
45
color_bar (minz, maxz) plots a color bar to the right of the plot square
46
labelled by the z values from minz to maxz.
49
color_bar (z (min, min), z (max, max))
52
plf (z, y, x, cmin = MINZ, cmax = MAXZ)
53
color_bar (MINZ, MAXZ)
58
ncol = 100 + (1 - split) * 100
60
if type (minz) == type (maxz) == type (1) : # Do not change!!!
61
plotval = reshape (arange (minz, maxz + 1, dtype = 'B'),
63
pli (plotval, xmin0, ymin, xmax0, ymax) # draw bar
65
pli (reshape (span (0, 1, ncol), (ncol, 1)),
66
xmin0, ymin, xmax0, ymax) # draw bar
68
pli (reshape (split_bytscl (span (0, 1, ncol), 0).astype ('B'), (ncol, 1)),
69
xmin0, ymin, xmax0, ymax) # draw bar
70
pldj (array ( [xmin0, xmin0]), array ( [ymin, ymax]), array ( [xmax0, xmax0]),
71
array ( [ymin, ymax]), color=color)
73
levs = nice_levels (array ( [minz, maxz]))
75
for i in range (len (levs)) :
76
scales.append ( "% .5g" % levs [i])
77
ys = ymin + (ymax - ymin) * (levs - minz) / (maxz - minz)
81
plt (scales [i], xmax0+0.005, ys [i], color=color) # labels
82
xmin = zeros (llev, Float)
83
xmax = zeros (llev, Float)
85
xmax [0:llev] = xmax0+0.005
87
pldj (xmin, ys, xmax, ys, color=color) # ticks
89
# Write the max and min on bar
90
xmid = (xmin0 + xmax0)/2.0
91
if max (ys) > (ymax-0.01):
92
plt ("% .5g" % maxz, xmid, ymax + 0.020, justify="CA",
95
plt ("% .5g" % maxz, xmid, ymax + 0.005, justify="CA",
97
plt ("% .5g" % minz, xmid, ymin - 0.0025, justify = "CT",
102
ymidpt = (ymax+ymin)/2.0
104
plt(zlabel, x0, ymidpt, color=color,
105
font=font, justify="CB", height=fontsize, orient=3)