Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a test case for compositing images with an alpha attribute
  • Loading branch information
Westacular committed May 3, 2013
commit 04ee71e886d4ff8e85d133dd811b587e342326a7
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ def test_image_composite_background():
ax.set_axis_bgcolor((1, 0, 0, 0.5))
ax.set_xlim([0, 12])

@image_comparison(baseline_images=['image_composite_alpha'], remove_text=True)
def test_image_composite_alpha():
"""
Tests that the alpha value is recognized and correctly applied in the
process of compositing images together.
"""
fig = plt.figure()
ax = fig.add_subplot(111)
arr = np.arange(12).reshape(4, 3)
ax.imshow(arr, extent=[0, 2, 15, 0], alpha=0.25)
ax.imshow(arr, extent=[4, 6, 15, 0], alpha=0.5)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if this image was RGBA? Would the alpha value still have any effect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image's alpha channel would be multiplied by the alpha value. So, an image with alphas ranging from 0.2 to 0.8 combined with alpha=0.5 would effectively be treated like an image with alphas in the 0.1 to 0.4 range. This seems reasonable, and it's already the way the backends that don't require this compositing behave.

But now that you point it out, this test case should probably involve that. I'll update it.

ax.imshow(arr, extent=[8, 10, 15, 0])
ax.imshow(arr.T, extent=[0, 12, 2, 4], alpha=0.25)
ax.imshow(arr.T, extent=[0, 12, 6, 8], alpha=0.5)
ax.imshow(arr.T, extent=[0, 12, 10, 12], alpha=1.0)
ax.set_axis_bgcolor((0, 0, 0, 0.5))
ax.set_xlim([0, 12])
ax.set_ylim([15, 0])


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)