Browse Source

Fix some corner cases in the plotting

Fixes #5
Vadim Markovtsev 8 years ago
parent
commit
f14a6bb68b
1 changed files with 5 additions and 3 deletions
  1. 5 3
      labours.py

+ 5 - 3
labours.py

@@ -75,7 +75,7 @@ def main():
         matrix = df.as_matrix()
         matrix = df.as_matrix()
         if "M" in args.resample:
         if "M" in args.resample:
             matrix[0] = row0
             matrix[0] = row0
-            for i in range(1, matrix.shape[0]):
+            for i in range(1, min(*matrix.shape)):
                 matrix[i, i] += matrix[i, :i].sum()
                 matrix[i, i] += matrix[i, :i].sum()
                 matrix[i, :i] = 0
                 matrix[i, :i] = 0
         if args.resample in ("year", "A"):
         if args.resample in ("year", "A"):
@@ -133,11 +133,13 @@ def main():
     if locs[0] < pyplot.xlim()[0]:
     if locs[0] < pyplot.xlim()[0]:
         del locs[0]
         del locs[0]
     endindex = -1
     endindex = -1
-    if pyplot.xlim()[1] - locs[-1] >= (locs[-1] - locs[-2]) / 2:
+    if len(locs) >= 2 and \
+            pyplot.xlim()[1] - locs[-1] >= (locs[-1] - locs[-2]) / 2:
         locs.append(pyplot.xlim()[1])
         locs.append(pyplot.xlim()[1])
         endindex = len(locs) - 1
         endindex = len(locs) - 1
     startindex = -1
     startindex = -1
-    if locs[0] - pyplot.xlim()[0] >= (locs[1] - locs[0]) / 2:
+    if len(locs) >= 2 and \
+            locs[0] - pyplot.xlim()[0] >= (locs[1] - locs[0]) / 2:
         locs.append(pyplot.xlim()[0])
         locs.append(pyplot.xlim()[0])
         startindex = len(locs) - 1
         startindex = len(locs) - 1
     pyplot.gca().set_xticks(locs)
     pyplot.gca().set_xticks(locs)