Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b0a9d4

Browse filesBrowse files
committed
BUGFIX: finish implementing true bbox fix
1 parent b8840cf commit 1b0a9d4
Copy full SHA for 1b0a9d4

File tree

8 files changed

+68
-35
lines changed
Filter options

8 files changed

+68
-35
lines changed

‎lib/matplotlib/backends/backend_cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_cairo.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform,
217217
self._fill_and_stroke(
218218
ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
219219

220-
def draw_image(self, gc, x, y, im, bbox=None):
220+
def draw_image(self, gc, x, y, im):
221221
im = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(im[::-1])
222222
surface = cairo.ImageSurface.create_for_data(
223223
im.ravel().data, cairo.FORMAT_ARGB32,

‎lib/matplotlib/backends/backend_mixed.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_mixed.py
+23-4Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ def _update_true_bbox(self, bbox, transform=None):
9292
else:
9393
self._true_bbox = Bbox.union([self._true_bbox, bbox])
9494

95+
def draw_path(self, gc, path, transform, rgbFace=None):
96+
if self._rasterizing > 0:
97+
bbox = Bbox.null()
98+
bbox.update_from_path(path, ignore=True)
99+
self._update_true_bbox(bbox, transform)
100+
return self._renderer.draw_path(gc, path, transform, rgbFace)
101+
102+
def draw_markers(self, gc, marker_path, marker_trans, path,
103+
trans, rgbFace=None):
104+
#TODO
105+
return self._renderer.draw_markers(
106+
gc, marker_path, marker_trans, path, trans, rgbFace)
107+
95108
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
96109
offsets, offsetTrans, facecolors, edgecolors,
97110
linewidths, linestyles, antialiaseds, urls,
@@ -124,6 +137,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
124137
gc, master_transform, meshWidth, meshHeight, coordinates,
125138
offsets, offsetTrans, facecolors, antialiased, edgecolors)
126139

140+
def draw_gouraud_triangle(self, gc, points, colors, transform):
141+
if self._rasterizing > 0:
142+
bbox = Bbox.null()
143+
bbox.update_from_data_xy(points, ignore=True)
144+
self._update_true_bbox(bbox, transform)
145+
return self._renderer.draw_gouraud_triangle(
146+
gc, points, colors, transform)
147+
127148
def start_rasterizing(self):
128149
"""
129150
Enter "raster" mode. All subsequent drawing commands (until
@@ -183,10 +204,8 @@ def stop_rasterizing(self):
183204
# requested, but that's better than the drawing not fitting
184205
# into the space requested, see Issue #6827
185206
self._renderer.draw_image(
186-
gc,
187-
self._true_bbox.x0,
188-
self._true_bbox.y0,
189-
image, bbox=self._true_bbox)
207+
gc, self._true_bbox.x0, self._true_bbox.y0, image,
208+
true_size=(self._true_bbox.width, self._true_bbox.height))
190209
self._raster_renderer = None
191210
self._rasterizing = False
192211

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,24 +1735,26 @@ def merge_used_characters(self, *args, **kwargs):
17351735
def get_image_magnification(self):
17361736
return self.image_dpi/72.0
17371737

1738-
def draw_image(self, gc, x, y, im, transform=None, bbox=None):
1738+
def option_true_bbox_image(self):
1739+
return True
1740+
1741+
def draw_image(self, gc, x, y, im, transform=None, true_size=None):
17391742
# docstring inherited
17401743

17411744
h, w = im.shape[:2]
17421745
if w == 0 or h == 0:
17431746
return
17441747

1745-
if bbox is not None:
1746-
h = bbox.height
1747-
w = bbox.width
1748+
if true_size is not None:
1749+
w, h = true_size
17481750

17491751
if transform is None:
17501752
# If there's no transform, alpha has already been applied
17511753
gc.set_alpha(1.0)
17521754

17531755
self.check_gc(gc)
17541756

1755-
if bbox is None:
1757+
if true_size is not None:
17561758
w = 72.0 * w / self.image_dpi
17571759
h = 72.0 * h / self.image_dpi
17581760

‎lib/matplotlib/backends/backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pgf.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,18 @@ def option_image_nocomposite(self):
639639
# docstring inherited
640640
return not mpl.rcParams['image.composite_image']
641641

642-
def draw_image(self, gc, x, y, im, transform=None, bbox=None):
642+
def option_true_bbox_image(self):
643+
return True
644+
645+
def draw_image(self, gc, x, y, im, transform=None, true_size=None):
643646
# docstring inherited
644647

645648
h, w = im.shape[:2]
646649
if w == 0 or h == 0:
647650
return
648651

649-
if bbox is not None:
650-
h = bbox.height
651-
w = bbox.width
652+
if true_size is not None:
653+
w, h = true_size
652654

653655
if not os.path.exists(getattr(self.fh, "name", "")):
654656
cbook._warn_external(

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+11-7Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,18 @@ def get_image_magnification(self):
280280
"""
281281
return self.image_magnification
282282

283-
def draw_image(self, gc, x, y, im, transform=None, bbox=None):
283+
def option_true_bbox_image(self):
284+
return True
285+
286+
def draw_image(self, gc, x, y, im, transform=None, true_size=None):
284287
# docstring inherited
285288

286289
h, w = im.shape[:2]
287290
if h == 0 or w == 0:
288291
return
289-
if bbox is not None:
290-
h = bbox.height
291-
w = bbox.width
292+
if true_size is not None:
293+
w, h = true_size
294+
292295
imagecmd = "false 3 colorimage"
293296
data = im[::-1, :, :3] # Vertically flipped rgb values.
294297
# data.tobytes().hex() has no spaces, so can be linewrapped by relying
@@ -297,13 +300,14 @@ def draw_image(self, gc, x, y, im, transform=None, bbox=None):
297300

298301
if transform is None:
299302
matrix = "1 0 0 1 0 0"
300-
if bbox is None:
303+
if true_size is None:
301304
xscale = w / self.image_magnification
302305
yscale = h / self.image_magnification
306+
else:
307+
xscale = 1.0
308+
yscale = 1.0
303309
else:
304310
matrix = " ".join(map(str, transform.frozen().to_values()))
305-
xscale = 1.0
306-
yscale = 1.0
307311

308312
bbox = gc.get_clip_rectangle()
309313
clippath, clippath_trans = gc.get_clip_path()

‎lib/matplotlib/backends/backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_svg.py
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,13 @@ def option_scale_image(self):
804804
# docstring inherited
805805
return True
806806

807+
def option_true_bbox_image(self):
808+
return True
809+
807810
def get_image_magnification(self):
808811
return self.image_dpi / 72.0
809812

810-
def draw_image(self, gc, x, y, im, transform=None, bbox=None):
813+
def draw_image(self, gc, x, y, im, transform=None, true_size=None):
811814
# docstring inherited
812815

813816
h, w = im.shape[:2]
@@ -851,13 +854,14 @@ def draw_image(self, gc, x, y, im, transform=None, bbox=None):
851854
w = 72.0 * w / self.image_dpi
852855
h = 72.0 * h / self.image_dpi
853856

854-
if bbox is not None:
857+
if true_size is not None:
858+
width, height = true_size
855859
# because rasterization happens only for integer pixels, the
856860
# round-trip width w = # int(width/72*image_dpi)*72/image_dpi
857861
# need not match the "real" width
858-
scale_x = bbox.width/w
859-
scale_y = bbox.height/h
860-
real_h = bbox.height
862+
scale_x = width/w
863+
scale_y = height/h
864+
real_h = height
861865
else:
862866
scale_x = 1
863867
scale_y = 1

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ def draw_path(self, gc, path, transform, rgbFace=None):
227227
gfx_ctx.StrokePath(wxpath)
228228
gc.unselect()
229229

230-
def draw_image(self, gc, x, y, im, bbox=None):
231-
if bbox is None:
232-
bbox = gc.get_clip_rectangle()
230+
def draw_image(self, gc, x, y, im):
231+
bbox = gc.get_clip_rectangle()
233232
if bbox is not None:
234233
l, b, w, h = bbox.bounds
235234
else:

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ def flush_images():
144144
gc = renderer.new_gc()
145145
gc.set_clip_rectangle(parent.bbox)
146146
gc.set_clip_path(parent.get_clip_path())
147-
if type(renderer) == mpl.backends.backend_agg.RendererAgg:
148-
renderer.draw_image(gc, l, b, im)
147+
if not hasattr(renderer, 'option_true_bbox_image'):
148+
renderer.draw_image(gc, round(l), round(b), data)
149149
else:
150-
renderer.draw_image(gc, round(l), round(b), data,
151-
bbox=parent.bbox)
150+
renderer.draw_image(
151+
gc, parent.bbox.x0, parent.bbox.y0, data,
152+
true_size=(parent.bbox.width, parent.bbox.height))
152153
gc.restore()
153154
del image_group[:]
154155

@@ -624,10 +625,12 @@ def draw(self, renderer, *args, **kwargs):
624625
im, l, b, trans = self.make_image(
625626
renderer, renderer.get_image_magnification())
626627
if im is not None:
627-
if type(renderer) == mpl.backends.backend_agg.RendererAgg:
628+
if not hasattr(renderer, 'option_true_bbox_image'):
628629
renderer.draw_image(gc, l, b, im)
629630
else:
630-
renderer.draw_image(gc, l, b, im, bbox=self.get_clip_box())
631+
bbox = self.get_clip_box()
632+
renderer.draw_image(gc, bbox.x0, bbox.y0, im, true_size=(
633+
bbox.width, bbox.height))
631634
gc.restore()
632635
self.stale = False
633636

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.