Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7e673d

Browse files
committed
Delay the cast to int in contour.py
This is to allow checking againt nan below Thangs @argriffing
1 parent a94e43f commit a7e673d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/matplotlib/contour.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,20 +474,21 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
474474
xy2 = mlab.less_simple_linear_interpolation(
475475
pl, lc, [xi[1]])
476476

477-
# Make integer
478-
I = [int(np.floor(I[0])), int(np.ceil(I[1]))]
477+
# Round to integer values but keep as float
478+
# To allow check against nan below
479+
I = [np.floor(I[0]), np.ceil(I[1])]
479480

480481
# Actually break contours
481482
if closed:
482483
# This will remove contour if shorter than label
483484
if np.all(~np.isnan(I)):
484-
nlc.append(np.r_[xy2, lc[I[1]:I[0] + 1], xy1])
485+
nlc.append(np.r_[xy2, lc[int(I[1]):int(I[0]) + 1], xy1])
485486
else:
486487
# These will remove pieces of contour if they have length zero
487488
if not np.isnan(I[0]):
488-
nlc.append(np.r_[lc[:I[0] + 1], xy1])
489+
nlc.append(np.r_[lc[:int(I[0]) + 1], xy1])
489490
if not np.isnan(I[1]):
490-
nlc.append(np.r_[xy2, lc[I[1]:]])
491+
nlc.append(np.r_[xy2, lc[int(I[1]):]])
491492

492493
# The current implementation removes contours completely
493494
# covered by labels. Uncomment line below to keep

0 commit comments

Comments
 (0)