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

Skip to content

Enables hatch alpha on SVG #16890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions doc/users/next_whats_new/2020-03-24-svg-hatch-alpha.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The SVG backend can now render hatches with transparency
--------------------------------------------------------

The SVG backend now respects the hatch stroke alpha. Useful applications are,
among others, semi-transparent hatches as a subtle way to differentiate columns
in bar plots.
13 changes: 8 additions & 5 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,19 @@ def _write_hatches(self):
x="0", y="0", width=str(HATCH_SIZE+1),
height=str(HATCH_SIZE+1),
fill=fill)
writer.element(
'path',
d=path_data,
style=generate_css({
hatch_style = {
'fill': rgb2hex(stroke),
'stroke': rgb2hex(stroke),
'stroke-width': str(mpl.rcParams['hatch.linewidth']),
'stroke-linecap': 'butt',
'stroke-linejoin': 'miter'
})
}
if stroke[3] < 1:
hatch_style['stroke-opacity'] = str(stroke[3])
writer.element(
'path',
d=path_data,
style=generate_css(hatch_style)
)
writer.end('pattern')
writer.end('defs')
Expand Down
Loading