Skip to content

Commit db55918

Browse files
authored
Merge pull request #16890 from mnmelo/patch-1
Enables hatch alpha on SVG
2 parents 0828170 + c939331 commit db55918

File tree

3 files changed

+83
-74
lines changed

3 files changed

+83
-74
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The SVG backend can now render hatches with transparency
2+
--------------------------------------------------------
3+
4+
The SVG backend now respects the hatch stroke alpha. Useful applications are,
5+
among others, semi-transparent hatches as a subtle way to differentiate columns
6+
in bar plots.

lib/matplotlib/backends/backend_svg.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,19 @@ def _write_hatches(self):
391391
x="0", y="0", width=str(HATCH_SIZE+1),
392392
height=str(HATCH_SIZE+1),
393393
fill=fill)
394-
writer.element(
395-
'path',
396-
d=path_data,
397-
style=generate_css({
394+
hatch_style = {
398395
'fill': rgb2hex(stroke),
399396
'stroke': rgb2hex(stroke),
400397
'stroke-width': str(mpl.rcParams['hatch.linewidth']),
401398
'stroke-linecap': 'butt',
402399
'stroke-linejoin': 'miter'
403-
})
400+
}
401+
if stroke[3] < 1:
402+
hatch_style['stroke-opacity'] = str(stroke[3])
403+
writer.element(
404+
'path',
405+
d=path_data,
406+
style=generate_css(hatch_style)
404407
)
405408
writer.end('pattern')
406409
writer.end('defs')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy