Skip to content

Commit b9d3422

Browse files
committed
Merge pull request #1894 from mdboom/image/composite_background
Fixes background coloring of multiple images on the same axes.
2 parents 4256538 + a082e6a commit b9d3422

File tree

7 files changed

+290
-3
lines changed

7 files changed

+290
-3
lines changed

doc/users/whats_new.rst

Lines 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

Lines 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.

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

Lines changed: 272 additions & 0 deletions
Loading

lib/matplotlib/tests/test_image.py

Lines 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

Lines 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)