From 5f68f646440e04630f3142d962503fafb14363b7 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 12:05:03 -0500 Subject: [PATCH 01/11] Change num lines to int in hatch. Fixes numpy issues warnings --- lib/matplotlib/hatch.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index e6df8bcfce6d..ad703bd0e72b 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -21,7 +21,7 @@ class HatchPatternBase: class HorizontalHatch(HatchPatternBase): def __init__(self, hatch, density): - self.num_lines = (hatch.count('-') + hatch.count('+')) * density + self.num_lines = int((hatch.count('-') + hatch.count('+')) * density) self.num_vertices = self.num_lines * 2 def set_vertices_and_codes(self, vertices, codes): @@ -38,7 +38,7 @@ def set_vertices_and_codes(self, vertices, codes): class VerticalHatch(HatchPatternBase): def __init__(self, hatch, density): - self.num_lines = (hatch.count('|') + hatch.count('+')) * density + self.num_lines = int((hatch.count('|') + hatch.count('+')) * density) self.num_vertices = self.num_lines * 2 def set_vertices_and_codes(self, vertices, codes): @@ -55,8 +55,8 @@ def set_vertices_and_codes(self, vertices, codes): class NorthEastHatch(HatchPatternBase): def __init__(self, hatch, density): - self.num_lines = (hatch.count('/') + hatch.count('x') + - hatch.count('X')) * density + self.num_lines = int((hatch.count('/') + hatch.count('x') + + hatch.count('X')) * density) if self.num_lines: self.num_vertices = (self.num_lines + 1) * 2 else: @@ -74,8 +74,8 @@ def set_vertices_and_codes(self, vertices, codes): class SouthEastHatch(HatchPatternBase): def __init__(self, hatch, density): - self.num_lines = (hatch.count('\\') + hatch.count('x') + - hatch.count('X')) * density + self.num_lines = int((hatch.count('\\') + hatch.count('x') + + hatch.count('X')) * density) self.num_vertices = (self.num_lines + 1) * 2 if self.num_lines: self.num_vertices = (self.num_lines + 1) * 2 @@ -100,8 +100,8 @@ def __init__(self, hatch, density): self.num_shapes = 0 self.num_vertices = 0 else: - self.num_shapes = ((self.num_rows / 2 + 1) * (self.num_rows + 1) + - (self.num_rows / 2) * (self.num_rows)) + self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) + + (self.num_rows // 2) * (self.num_rows)) self.num_vertices = (self.num_shapes * len(self.shape_vertices) * (self.filled and 1 or 2)) @@ -212,6 +212,7 @@ def get_path(hatchpattern, density=6): cursor = 0 for pattern in patterns: if pattern.num_vertices != 0: + num_vertices vertices_chunk = vertices[cursor:cursor + pattern.num_vertices] codes_chunk = codes[cursor:cursor + pattern.num_vertices] pattern.set_vertices_and_codes(vertices_chunk, codes_chunk) From 687f1f8e2637a7f2a54d069902996151261dd246 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 12:06:31 -0500 Subject: [PATCH 02/11] Index with an integer in test_axes --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 638e4907095a..45d791341d30 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -523,7 +523,7 @@ def test_nonfinite_limits(): y = np.log(x) finally: np.seterr(**olderr) - x[len(x)/2] = np.nan + x[len(x)//2] = np.nan fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) From 4d3b23abe1928d22ac9c3531f6415d1c1c1f9247 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 12:12:15 -0500 Subject: [PATCH 03/11] Number of verts in simplification is an int Fixes numpy warnings in indexing --- lib/matplotlib/tests/test_simplification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_simplification.py b/lib/matplotlib/tests/test_simplification.py index a1bc217bf6fd..e99ac097a989 100644 --- a/lib/matplotlib/tests/test_simplification.py +++ b/lib/matplotlib/tests/test_simplification.py @@ -153,7 +153,7 @@ def test_start_with_moveto(): decodebytes = base64.decodestring verts = np.fromstring(decodebytes(data), dtype=' Date: Sat, 12 Jul 2014 13:19:21 -0500 Subject: [PATCH 04/11] Explicite cast to int in colors --- lib/matplotlib/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index dbc96197c134..84b8efca403f 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -222,7 +222,7 @@ def is_color_like(c): def rgb2hex(rgb): 'Given an rgb or rgba sequence of 0-1 floats, return the hex string' - return '#%02x%02x%02x' % tuple([np.round(val * 255) for val in rgb[:3]]) + return '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]]) hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z") From 82496ee81bdb3a32f7445bb2b6d946bb1e0b099f Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 13:32:06 -0500 Subject: [PATCH 05/11] Cast steps to integer in cbook --- lib/matplotlib/cbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index d0978fa46d92..e0da386583d3 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1737,7 +1737,7 @@ def simple_linear_interpolation(a, steps): if steps == 1: return a - steps = np.floor(steps) + steps = int(np.floor(steps)) new_length = ((len(a) - 1) * steps) + 1 new_shape = list(a.shape) new_shape[0] = new_length From d7a5c8e19209c85221abfd55cf3ba07b0fd81baf Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 13:39:56 -0500 Subject: [PATCH 06/11] Cast to integer in bezier for indexing --- lib/matplotlib/bezier.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/bezier.py b/lib/matplotlib/bezier.py index 034aa1d45cd1..efa657795a15 100644 --- a/lib/matplotlib/bezier.py +++ b/lib/matplotlib/bezier.py @@ -256,7 +256,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False): for ctl_points, command in path_iter: iold = i - i += len(ctl_points) / 2 + i += len(ctl_points) // 2 if inside(ctl_points[-2:]) != begin_inside: bezier_path = concat([ctl_points_old[-2:], ctl_points]) break @@ -286,7 +286,6 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False): verts_right = right[:] #i += 1 - if path.codes is None: path_in = Path(concat([path.vertices[:i], verts_left])) path_out = Path(concat([verts_right, path.vertices[i:]])) From dc87d3b3eab3499ef9e103218dc425819f46fa48 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 13:58:51 -0500 Subject: [PATCH 07/11] Cast to integer in contour as suggested by comment --- lib/matplotlib/bezier.py | 1 + lib/matplotlib/contour.py | 2 +- lib/matplotlib/hatch.py | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/bezier.py b/lib/matplotlib/bezier.py index efa657795a15..ce2c9d5052a1 100644 --- a/lib/matplotlib/bezier.py +++ b/lib/matplotlib/bezier.py @@ -286,6 +286,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False): verts_right = right[:] #i += 1 + if path.codes is None: path_in = Path(concat([path.vertices[:i], verts_left])) path_out = Path(concat([verts_right, path.vertices[i:]])) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 383978cbc44d..9de179f355c0 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -475,7 +475,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5): pl, lc, [xi[1]]) # Make integer - I = [np.floor(I[0]), np.ceil(I[1])] + I = [int(np.floor(I[0])), int(np.ceil(I[1]))] # Actually break contours if closed: diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index ad703bd0e72b..6729b610997c 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -212,7 +212,6 @@ def get_path(hatchpattern, density=6): cursor = 0 for pattern in patterns: if pattern.num_vertices != 0: - num_vertices vertices_chunk = vertices[cursor:cursor + pattern.num_vertices] codes_chunk = codes[cursor:cursor + pattern.num_vertices] pattern.set_vertices_and_codes(vertices_chunk, codes_chunk) From 8993188032f29bf94c2bb1e2aaefaab918354153 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 14:36:54 -0500 Subject: [PATCH 08/11] Integer division in mlab test --- lib/matplotlib/tests/test_mlab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_mlab.py b/lib/matplotlib/tests/test_mlab.py index 0cc991f05ebf..5dcb5d790d37 100644 --- a/lib/matplotlib/tests/test_mlab.py +++ b/lib/matplotlib/tests/test_mlab.py @@ -1325,8 +1325,8 @@ def createStim(self, fstims, iscomplex, sides, nsides, len_x=None, freqs_specgram = freqs_density # time points for specgram - t_start = NFFT_specgram_real/2 - t_stop = len(x) - NFFT_specgram_real/2+1 + t_start = NFFT_specgram_real//2 + t_stop = len(x) - NFFT_specgram_real//2+1 t_step = NFFT_specgram_real - nover_specgram_real t_specgram = x[t_start:t_stop:t_step] if NFFT_specgram_real % 2: From 2c37ba1079f8ed7a07d1a9b8d3627622243e472f Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 12 Jul 2014 14:40:55 -0500 Subject: [PATCH 09/11] Integer division in trirefine --- lib/matplotlib/colors.py | 3 ++- lib/matplotlib/tri/trirefine.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 84b8efca403f..5d165b8f69a0 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -222,7 +222,8 @@ def is_color_like(c): def rgb2hex(rgb): 'Given an rgb or rgba sequence of 0-1 floats, return the hex string' - return '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]]) + a = '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]]) + return a hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z") diff --git a/lib/matplotlib/tri/trirefine.py b/lib/matplotlib/tri/trirefine.py index ae2f257a1f5e..11e3fff3e468 100644 --- a/lib/matplotlib/tri/trirefine.py +++ b/lib/matplotlib/tri/trirefine.py @@ -231,7 +231,7 @@ def _refine_triangulation_once(triangulation, ancestors=None): # points # hint: each apex is shared by 2 masked_triangles except the borders. borders = np.sum(neighbors == -1) - added_pts = (3*ntri + borders) / 2 + added_pts = (3*ntri + borders) // 2 refi_npts = npts + added_pts refi_x = np.zeros(refi_npts) refi_y = np.zeros(refi_npts) From a94e43faaa61901d201ee798c5f8827ce18eecd6 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Wed, 23 Jul 2014 09:37:36 +0200 Subject: [PATCH 10/11] Remove redundant cast to int --- lib/matplotlib/cbook.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index e0da386583d3..f538e238542a 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1747,7 +1747,6 @@ def simple_linear_interpolation(a, steps): a0 = a[0:-1] a1 = a[1:] delta = ((a1 - a0) / steps) - steps = int(steps) for i in range(1, steps): result[i::steps] = delta * i + a0 result[steps::steps] = a1 From a7e673ddcdf46374566e1e1689a57cf3512b7de7 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Wed, 23 Jul 2014 09:46:27 +0200 Subject: [PATCH 11/11] Delay the cast to int in contour.py This is to allow checking againt nan below Thangs @argriffing --- lib/matplotlib/contour.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 9de179f355c0..0d74a3a8461d 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -474,20 +474,21 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5): xy2 = mlab.less_simple_linear_interpolation( pl, lc, [xi[1]]) - # Make integer - I = [int(np.floor(I[0])), int(np.ceil(I[1]))] + # Round to integer values but keep as float + # To allow check against nan below + I = [np.floor(I[0]), np.ceil(I[1])] # Actually break contours if closed: # This will remove contour if shorter than label if np.all(~np.isnan(I)): - nlc.append(np.r_[xy2, lc[I[1]:I[0] + 1], xy1]) + nlc.append(np.r_[xy2, lc[int(I[1]):int(I[0]) + 1], xy1]) else: # These will remove pieces of contour if they have length zero if not np.isnan(I[0]): - nlc.append(np.r_[lc[:I[0] + 1], xy1]) + nlc.append(np.r_[lc[:int(I[0]) + 1], xy1]) if not np.isnan(I[1]): - nlc.append(np.r_[xy2, lc[I[1]:]]) + nlc.append(np.r_[xy2, lc[int(I[1]):]]) # The current implementation removes contours completely # covered by labels. Uncomment line below to keep