Skip to content

Commit 8c7361d

Browse files
committed
fix some code that breaks python 2.4
svn path=/trunk/matplotlib/; revision=8499
1 parent 729422c commit 8c7361d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

examples/api/hinton_demo.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def hinton(W, maxWeight=None, ax=None):
1010
"""
11-
Draws a Hinton diagram for visualizing a weight matrix.
11+
Draws a Hinton diagram for visualizing a weight matrix.
1212
"""
1313
if not ax:
1414
fig = plt.figure()
@@ -23,13 +23,14 @@ def hinton(W, maxWeight=None, ax=None):
2323
ax.yaxis.set_major_locator(NullLocator())
2424

2525
for (x,y),w in np.ndenumerate(W):
26-
color = 'white' if w > 0 else 'black'
26+
if w > 0: color = 'white'
27+
else: color = 'black'
2728
size = np.sqrt(np.abs(w))
2829
rect = Rectangle([x - size / 2, y - size / 2], size, size,
2930
facecolor=color, edgecolor=color)
3031
ax.add_patch(rect)
3132
ax.autoscale_view()
32-
33+
3334
# Reverse the yaxis limits
3435
ax.set_ylim(*ax.get_ylim()[::-1])
3536

lib/mpl_toolkits/axisartist/angle_helper.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ class FormatterHMS(object):
179179
def __call__(self, direction, factor, values): # hour
180180
if len(values) == 0:
181181
return []
182-
ss = [[-1, 1][v>0] for v in values]
182+
#ss = [[-1, 1][v>0] for v in values] #not py24 compliant
183+
values = np.asarray(values)
184+
ss = np.where(values>0, 1, -1)
183185
values = np.abs(values)/15.
184186

185187
if factor == 1:
@@ -221,7 +223,9 @@ class FormatterDMS(object):
221223
def __call__(self, direction, factor, values):
222224
if len(values) == 0:
223225
return []
224-
ss = [[-1, 1][v>0] for v in values]
226+
#ss = [[-1, 1][v>0] for v in values] #not py24 compliant
227+
values = np.asarray(values)
228+
ss = np.where(values>0, 1, -1)
225229
values = np.abs(values)
226230
if factor == 1:
227231
return ["$%d^{\circ}$" % (s*int(v),) for (s, v) in zip(ss, values)]

0 commit comments

Comments
 (0)