Skip to content

Navigation Menu

Sign in
Appearance settings

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 faebb37

Browse filesBrowse files
committed
Fix matplotlib#1894: Composite images do not have a transparent background
1 parent 4256538 commit faebb37
Copy full SHA for faebb37

File tree

Expand file treeCollapse file tree

6 files changed

+284
-3
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+284
-3
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _draw_unsampled_image(self, renderer, gc):
315315

316316
fc = self.axes.patch.get_facecolor()
317317
bg = mcolors.colorConverter.to_rgba(fc, 0)
318-
im.set_bg( *bg)
318+
im.set_bg(*bg)
319319

320320
# image input dimensions
321321
im.reset_matrix()
@@ -1078,7 +1078,7 @@ def get_window_extent(self, renderer=None):
10781078

10791079
def contains(self, mouseevent):
10801080
"""Test whether the mouse event occured within the image."""
1081-
if callable(self._contains):
1081+
if callable(self._contains):
10821082
return self._contains(self, mouseevent)
10831083

10841084
if not self.get_visible():# or self.get_figure()._renderer is None:
Binary file not shown.
Loading

‎lib/matplotlib/tests/baseline_images/test_image/image_composite_background.svg

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/baseline_images/test_image/image_composite_background.svg
+272Lines changed: 272 additions & 0 deletions
Loading

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ def test_image_edges():
225225

226226
assert g != 100, 'Expected a non-green edge - but sadly, it was.'
227227

228+
@image_comparison(baseline_images=['image_composite_background'], remove_text=True)
229+
def test_image_composite_background():
230+
fig = plt.figure()
231+
ax = fig.add_subplot(111)
232+
np.random.seed(0)
233+
ax.imshow(np.random.rand(15, 15), extent=[0, 2, 15, 0])
234+
ax.imshow(np.random.rand(15, 15), extent=[4, 6, 15, 0])
235+
ax.set_axis_bgcolor('k')
236+
ax.set_xlim([0, 12])
228237

229238
if __name__=='__main__':
230239
import nose

‎src/_image.cpp

Copy file name to clipboardExpand all lines: src/_image.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ _image_module::from_images(const Py::Tuple& args)
820820
pixfmt pixf(*imo->rbufOut);
821821
renderer_base rb(pixf);
822822

823-
rb.clear(agg::rgba(1, 1, 1, 1));
823+
rb.clear(agg::rgba(1, 1, 1, 0));
824824
for (size_t imnum = 0; imnum < N; imnum++)
825825
{
826826
tup = Py::Tuple(tups[imnum]);

0 commit comments

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