Skip to content

Fixing Issue #21879 Changed int to round in backend_agg.py #27465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, width, height, dpi):
self.dpi = dpi
self.width = width
self.height = height
self._renderer = _RendererAgg(int(width), int(height), dpi)
self._renderer = _RendererAgg(round(width), round(height), dpi)
self._filter_renderers = []

self._update_methods()
Expand Down Expand Up @@ -99,7 +99,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
if (npts > nmax > 100 and path.should_simplify and
rgbFace is None and gc.get_hatch() is None):
nch = np.ceil(npts / nmax)
chsize = int(np.ceil(npts / nch))
chsize = round(np.ceil(npts / nch))
i0 = np.arange(0, npts, chsize)
i1 = np.zeros_like(i0)
i1[:-1] = i0[1:] - 1
Expand Down Expand Up @@ -314,8 +314,8 @@ def restore_region(self, region, bbox=None, xy=None):

# The incoming data is float, but the _renderer type-checking wants
# to see integers.
self._renderer.restore_region(region, int(x1), int(y1),
int(x2), int(y2), int(ox), int(oy))
self._renderer.restore_region(region, round(x1), round(y1),
round(x2), round(y2), round(ox), round(oy))

else:
self._renderer.restore_region(region)
Expand All @@ -325,7 +325,7 @@ def start_filter(self):
Start filtering. It simply creates a new canvas (the old one is saved).
"""
self._filter_renderers.append(self._renderer)
self._renderer = _RendererAgg(int(self.width), int(self.height),
self._renderer = _RendererAgg(round(self.width), round(self.height),
self.dpi)
self._update_methods()

Expand Down Expand Up @@ -360,7 +360,7 @@ def post_processing(image, dpi):
if img.dtype.kind == 'f':
img = np.asarray(img * 255., np.uint8)
self._renderer.draw_image(
gc, slice_x.start + ox, int(self.height) - slice_y.stop + oy,
gc, slice_x.start + ox, round(self.height) - slice_y.stop + oy,
img[::-1])


Expand Down Expand Up @@ -499,7 +499,7 @@ def print_to_buffer(self):
FigureCanvasAgg.draw(self)
renderer = self.get_renderer()
return (bytes(renderer.buffer_rgba()),
(int(renderer.width), int(renderer.height)))
(round(renderer.width), round(renderer.height)))

# Note that these methods should typically be called via savefig() and
# print_figure(), and the latter ensures that `self.figure.dpi` already
Expand Down