Skip to content

Make hatch colour an rcParam. #7415

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 1 commit into from
Nov 7, 2016
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
Make hatch colour an rcParam.
  • Loading branch information
QuLogic committed Nov 7, 2016
commit 112a901b25aab4b958ccb7134ed6bd5bc859a29d
15 changes: 9 additions & 6 deletions doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,20 @@ To restore the previous behavior explicitly pass the keyword argument
Hatching
========

The width of the lines in a hatch pattern is now configurable by the
rcParam `hatch.linewidth`, with a default of 1 point. The old
behavior was different depending on backend:
The color and width of the lines in a hatch pattern are now configurable by the
rcParams `hatch.color` and `hatch.linewidth`, with defaults of black and 1
point, respectively. The old behaviour for the color was to apply the edge
color or use black, depending on the artist; the old behavior for the line
width was different depending on backend:

- PDF: 0.1 pt
- SVG: 1.0 pt
- PS: 1 px
- Agg: 1 px

The old behavior can not be restored across all backends simultaneously, but
can be restored for a single backend by setting::
The old color behavior can not be restored. The old line width behavior can not
be restored across all backends simultaneously, but can be restored for a
single backend by setting::

mpl.rcParams['hatch.linewidth'] = 0.1 # previous pdf hatch linewidth
mpl.rcParams['hatch.linewidth'] = 1.0 # previous svg hatch linewidth
Expand All @@ -620,7 +623,7 @@ The behavior of the PS and Agg backends was DPI dependent, thus::
mpl.rcParams['hatch.linewidth'] = 1.0 / dpi # previous ps and Agg hatch linewidth


There is no API level control of the hatch linewidth.
There is no API level control of the hatch color or linewidth.


.. _default_changes_font:
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ def __init__(self):
self._linewidth = 1
self._rgb = (0.0, 0.0, 0.0, 1.0)
self._hatch = None
self._hatch_color = colors.to_rgba(rcParams['hatch.color'])
self._hatch_linewidth = rcParams['hatch.linewidth']
self._url = None
self._gid = None
Expand Down Expand Up @@ -1104,6 +1105,12 @@ def get_hatch_path(self, density=6.0):
return None
return Path.hatch(self._hatch, density)

def get_hatch_color(self):
"""
Gets the color to use for hatching.
"""
return self._hatch_color

def get_hatch_linewidth(self):
"""
Gets the linewidth to use for hatching.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ def hatch_cmd(self, hatch):
else:
return [Name('DeviceRGB'), Op.setcolorspace_nonstroke]
else:
hatch_style = (self._rgb, self._fillcolor, hatch)
hatch_style = (self._hatch_color, self._fillcolor, hatch)
name = self.file.hatchPattern(hatch_style)
return [Name('Pattern'), Op.setcolorspace_nonstroke,
name, Op.setcolor_nonstroke]
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
if hatch:
hatch_name = self.create_hatch(hatch)
write("gsave\n")
write("[/Pattern [/DeviceRGB]] setcolorspace %f %f %f " % gc.get_rgb()[:3])
write("[/Pattern [/DeviceRGB]] setcolorspace %f %f %f " % gc.get_hatch_color()[:3])
write("%s setcolor fill grestore\n" % hatch_name)

if stroke:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def _get_hatch(self, gc, rgbFace):
"""
if rgbFace is not None:
rgbFace = tuple(rgbFace)
edge = gc.get_rgb()
edge = gc.get_hatch_color()
if edge is not None:
edge = tuple(edge)
dictkey = (gc.get_hatch(), rgbFace, edge)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ patch.force_edgecolor : True
patch.edgecolor : k
patch.antialiased : True # render patches in antialiased (no jaggies)

hatch.color : k
hatch.linewidth : 1.0

hist.bins : 10
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ def validate_animation_writer_path(p):
'patch.antialiased': [True, validate_bool], # antialiased (no jaggies)

## hatch props
'hatch.color': ['k', validate_color],
'hatch.linewidth': [1.0, validate_float],

## Histogram properties
Expand Down
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