Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7887018

Browse files
committed
Merge pull request #1193 from mdboom/cairo/alpha-handling
Cairo backend ignores alpha in imshow.
2 parents 7466e06 + b81313a commit 7887018

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ def draw_image(self, gc, x, y, im):
177177

178178
ctx.save()
179179
ctx.set_source_surface (surface, x, y)
180-
ctx.paint()
180+
if gc.get_alpha() != 1.0:
181+
ctx.paint_with_alpha(gc.get_alpha())
182+
else:
183+
ctx.paint()
181184
ctx.restore()
182185

183186
im.flipud_out()
@@ -465,17 +468,17 @@ def _save (self, fo, format, **kwargs):
465468
width_in_points)
466469

467470
if format == 'ps':
468-
if not cairo.HAS_PS_SURFACE:
471+
if not hasattr(cairo, 'PSSurface'):
469472
raise RuntimeError ('cairo has not been compiled with PS '
470473
'support enabled')
471474
surface = cairo.PSSurface (fo, width_in_points, height_in_points)
472475
elif format == 'pdf':
473-
if not cairo.HAS_PDF_SURFACE:
476+
if not hasattr(cairo, 'PDFSurface'):
474477
raise RuntimeError ('cairo has not been compiled with PDF '
475478
'support enabled')
476479
surface = cairo.PDFSurface (fo, width_in_points, height_in_points)
477480
elif format in ('svg', 'svgz'):
478-
if not cairo.HAS_SVG_SURFACE:
481+
if not hasattr(cairo, 'SVGSurface'):
479482
raise RuntimeError ('cairo has not been compiled with SVG '
480483
'support enabled')
481484
if format == 'svgz':

0 commit comments

Comments
 (0)