diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 34fd38713bec..0ef4d78e35ca 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -29,6 +29,12 @@ The individual items of a collection may now have different alpha values and be rendered correctly. This also fixes a bug where collections were always filled in the PDF backend. +Multiple images on same axes are correctly transparent +------------------------------------------------------ + +When putting multiple images onto the same axes, the background color +of the axes will now show through correctly. + .. _whats-new-1-2: new in matplotlib-1.2 diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index f1292309bdbe..0eb2f9a1a9ec 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -315,7 +315,7 @@ def _draw_unsampled_image(self, renderer, gc): fc = self.axes.patch.get_facecolor() bg = mcolors.colorConverter.to_rgba(fc, 0) - im.set_bg( *bg) + im.set_bg(*bg) # image input dimensions im.reset_matrix() @@ -1078,7 +1078,7 @@ def get_window_extent(self, renderer=None): def contains(self, mouseevent): """Test whether the mouse event occured within the image.""" - if callable(self._contains): + if callable(self._contains): return self._contains(self, mouseevent) if not self.get_visible():# or self.get_figure()._renderer is None: diff --git a/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.pdf b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.pdf new file mode 100644 index 000000000000..8de059db2b5d Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.png b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.png new file mode 100644 index 000000000000..9123295c3717 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.svg b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.svg new file mode 100644 index 000000000000..dbb77184e0cb --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_image/image_composite_background.svg @@ -0,0 +1,272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 27c9992c9be8..894d3cb5607d 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -225,6 +225,15 @@ def test_image_edges(): assert g != 100, 'Expected a non-green edge - but sadly, it was.' +@image_comparison(baseline_images=['image_composite_background'], remove_text=True) +def test_image_composite_background(): + fig = plt.figure() + ax = fig.add_subplot(111) + arr = np.arange(12).reshape(4, 3) + ax.imshow(arr, extent=[0, 2, 15, 0]) + ax.imshow(arr, extent=[4, 6, 15, 0]) + ax.set_axis_bgcolor((1, 0, 0, 0.5)) + ax.set_xlim([0, 12]) if __name__=='__main__': import nose diff --git a/src/_image.cpp b/src/_image.cpp index f0d91c168aee..49feb530afac 100644 --- a/src/_image.cpp +++ b/src/_image.cpp @@ -820,7 +820,7 @@ _image_module::from_images(const Py::Tuple& args) pixfmt pixf(*imo->rbufOut); renderer_base rb(pixf); - rb.clear(agg::rgba(1, 1, 1, 1)); + rb.clear(agg::rgba(0, 0, 0, 0)); for (size_t imnum = 0; imnum < N; imnum++) { tup = Py::Tuple(tups[imnum]);