Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Milestone
Description
On master.
The following test is taken from test_images.test_image_composite_alpha:
from pylab import *fig = plt.figure()ax = fig.add_subplot(111)arr = np.zeros((11, 21, 4))arr[:, :, 0] = 1arr[:, :, 3] = np.concatenate((np.arange(0, 1.1, 0.1), np.arange(0, 1, 0.1)[::-1]))arr2 = np.zeros((21, 11, 4))arr2[:, :, 0] = 1arr2[:, :, 1] = 1arr2[:, :, 3] = np.concatenate((np.arange(0, 1.1, 0.1), np.arange(0, 1, 0.1)[::-1]))[:, np.newaxis]ax.imshow(arr, extent=[1, 2, 5, 0], alpha=0.3)ax.imshow(arr, extent=[2, 3, 5, 0], alpha=0.6)ax.imshow(arr, extent=[3, 4, 5, 0])ax.imshow(arr2, extent=[0, 5, 1, 2])ax.imshow(arr2, extent=[0, 5, 2, 3], alpha=0.6)ax.imshow(arr2, extent=[0, 5, 3, 4], alpha=0.3)ax.set_facecolor((0, 0.5, 0, 1))ax.set_xlim([0, 5])ax.set_ylim([5, 0])show()
By default, Agg produces the following result:
Matplotlib can also force software composition of overlapping images, which is, I guess, faster for vector backends (only one image ends up written to the file). For Agg, this is disabled; the Agg renderer does the compositing itself. But you can switch Agg back to use software composition with the following patch:
diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.pyindex c6af41b19..580cf0cf8 100644--- a/lib/matplotlib/backends/backend_agg.py+++ b/lib/matplotlib/backends/backend_agg.py@@ -302,7 +302,7 @@ class RendererAgg(RendererBase): # It is generally faster to composite each image directly to # the Figure, and there's no file size benefit to compositing # with the Agg backend- return True+ return False def option_scale_image(self): """
With the patch on, the result is clearly different.
I haven't looked much into which one is correct (it should be easy to manually compute the result), althoughhttps://github.com/anntzer/mpl_cairo seems to agree visually with Matplotlib, not Agg.