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

Skip to content

Commit 3ea6cfa

Browse files
committed
Remove unnecessary calls to float() before division.
Most of these calls probably date back to the time before `__future__`-division existed... Note that this will have the side effect that some functions that were accidentally accepting strings instead of floats before will no longer accept strings -- which seems fine to me.
1 parent b2a9e10 commit 3ea6cfa

30 files changed

Lines changed: 76 additions & 85 deletions

examples/api/mathtext_asarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
r'some other string', color='red', fontsize=20, dpi=200)
2323

2424
fig = plt.figure()
25-
fig.figimage(rgba1.astype(float)/255., 100, 100)
26-
fig.figimage(rgba2.astype(float)/255., 100, 300)
25+
fig.figimage(rgba1, 100, 100)
26+
fig.figimage(rgba2, 100, 300)
2727

2828
plt.show()

examples/color/color_cycle_default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
colors = prop_cycle.by_key()['color']
1414

1515
lwbase = plt.rcParams['lines.linewidth']
16-
thin = float('%.1f' % (lwbase / 2))
16+
thin = lwbase / 2
1717
thick = lwbase * 3
1818

1919
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True)
@@ -29,7 +29,7 @@
2929

3030
axs[1, icol].set_facecolor('k')
3131
axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2))
32-
axs[0, icol].set_title('line widths (pts): %.1f, %.1f' % (lwx, lwy),
32+
axs[0, icol].set_title('line widths (pts): %g, %g' % (lwx, lwy),
3333
fontsize='medium')
3434

3535
for irow in range(2):

examples/lines_bars_and_markers/stackplot_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def bump(a):
4343
y = 2 * np.random.random() - .5
4444
z = 10 / (.1 + np.random.random())
4545
for i in range(m):
46-
w = (i / float(m) - y) * z
46+
w = (i / m - y) * z
4747
a[i] += x * np.exp(-w * w)
4848
a = np.zeros((m, n))
4949
for i in range(n):

examples/statistics/hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
N, bins, patches = axs[0].hist(x, bins=n_bins)
5353

5454
# We'll color code by height, but you could use any scalar
55-
fracs = N.astype(float) / N.max()
55+
fracs = N / N.max()
5656

5757
# we need to normalize the data to 0..1 for the full range of the colormap
5858
norm = colors.Normalize(fracs.min(), fracs.max())

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6490,7 +6490,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64906490
if stacked and density:
64916491
db = np.diff(bins)
64926492
for m in tops:
6493-
m[:] = (m.astype(float) / db) / tops[-1].sum()
6493+
m[:] = (m / db) / tops[-1].sum()
64946494
if cumulative:
64956495
slc = slice(None)
64966496
if cbook.is_numlike(cumulative) and cumulative < 0:

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
146146

147147
if (nmax > 100 and npts > nmax and path.should_simplify and
148148
rgbFace is None and gc.get_hatch() is None):
149-
nch = np.ceil(npts / float(nmax))
149+
nch = np.ceil(npts / nmax)
150150
chsize = int(np.ceil(npts / nch))
151151
i0 = np.arange(0, npts, chsize)
152152
i1 = np.zeros_like(i0)

lib/matplotlib/backends/backend_mixed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def stop_rasterizing(self):
139139
# backends support this.
140140
self._renderer.draw_image(
141141
gc,
142-
float(l) / self.dpi * self._figdpi,
143-
(float(height)-b-h) / self.dpi * self._figdpi,
142+
l * self._figdpi / self.dpi,
143+
(height-b-h) * self._figdpi / self.dpi,
144144
image)
145145
self._raster_renderer = None
146146
self._rasterizing = False

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ def writeGouraudTriangles(self):
12821282
flat_colors = colors.reshape((shape[0] * shape[1], 4))
12831283
points_min = np.min(flat_points, axis=0) - (1 << 8)
12841284
points_max = np.max(flat_points, axis=0) + (1 << 8)
1285-
factor = float(0xffffffff) / (points_max - points_min)
1285+
factor = 0xffffffff / (points_max - points_min)
12861286

12871287
self.beginStream(
12881288
ob.id, None,

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
800800
flat_colors = colors.reshape((shape[0] * shape[1], 4))
801801
points_min = np.min(flat_points, axis=0) - (1 << 12)
802802
points_max = np.max(flat_points, axis=0) + (1 << 12)
803-
factor = np.ceil(float(2 ** 32 - 1) / (points_max - points_min))
803+
factor = np.ceil((2 ** 32 - 1) / (points_max - points_min))
804804

805805
xmin, ymin = points_min
806806
xmax, ymax = points_max

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def _onMouseWheel(self, evt):
10991099
delta = evt.GetWheelDelta()
11001100
rotation = evt.GetWheelRotation()
11011101
rate = evt.GetLinesPerAction()
1102-
step = rate * float(rotation) / delta
1102+
step = rate * rotation / delta
11031103

11041104
# Done handling event
11051105
evt.Skip()

0 commit comments

Comments
 (0)