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 a082e6a

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

File tree

Expand file treeCollapse file tree

7 files changed

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

7 files changed

+290
-3
lines changed

‎doc/users/whats_new.rst

Copy file name to clipboardExpand all lines: doc/users/whats_new.rst
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ The individual items of a collection may now have different alpha
2929
values and be rendered correctly. This also fixes a bug where
3030
collections were always filled in the PDF backend.
3131

32+
Multiple images on same axes are correctly transparent
33+
------------------------------------------------------
34+
35+
When putting multiple images onto the same axes, the background color
36+
of the axes will now show through correctly.
37+
3238
.. _whats-new-1-2:
3339

3440
new in matplotlib-1.2

‎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+
arr = np.arange(12).reshape(4, 3)
233+
ax.imshow(arr, extent=[0, 2, 15, 0])
234+
ax.imshow(arr, extent=[4, 6, 15, 0])
235+
ax.set_axis_bgcolor((1, 0, 0, 0.5))
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(0, 0, 0, 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.