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

Skip to content

Commit 949056c

Browse files
committed
Merge pull request #6198 from mdboom/hatch-edge-width
ENH/API: Make hatch linewidth an rcParam This also changes the default hatch width on some backends.
2 parents 6f167ca + f95cccd commit 949056c

19 files changed

+34
-4
lines changed

doc/users/whats_new/style_changes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ Plots
3535
the rcParam ``lines.markersize`` so it is consistent with ``plot(X,
3636
Y, 'o')``. The old value was 20, and the new value is 36 (6^2).
3737

38+
Hatching
39+
````````
40+
41+
- The width of the lines in a hatch pattern is now configurable by the
42+
rcParam `hatch.linewidth`, with a default of 1 point. The old
43+
behavior was different depending on backend:
44+
45+
- PDF: 0.1 pt
46+
- SVG: 1.0 pt
47+
- PS: 1 px
48+
- Agg: 1 px
49+
3850
Plot layout
3951
```````````
4052

lib/matplotlib/backend_bases.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ def __init__(self):
792792
self._linewidth = 1
793793
self._rgb = (0.0, 0.0, 0.0, 1.0)
794794
self._hatch = None
795+
self._hatch_linewidth = rcParams['hatch.linewidth']
795796
self._url = None
796797
self._gid = None
797798
self._snap = None
@@ -1111,6 +1112,12 @@ def get_hatch_path(self, density=6.0):
11111112
return None
11121113
return Path.hatch(self._hatch, density)
11131114

1115+
def get_hatch_linewidth(self):
1116+
"""
1117+
Gets the linewidth to use for hatching.
1118+
"""
1119+
return self._hatch_linewidth
1120+
11141121
def get_sketch_params(self):
11151122
"""
11161123
Returns the sketch parameters for the artist.

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ def writeHatches(self):
11821182
0, 0, sidelen, sidelen, Op.rectangle,
11831183
Op.fill)
11841184

1185-
self.output(0.1, Op.setlinewidth)
1185+
self.output(rcParams['hatch.linewidth'], Op.setlinewidth)
11861186

11871187
# TODO: We could make this dpi-dependent, but that would be
11881188
# an API change

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def create_hatch(self, hatch):
303303
if hatch in self._hatches:
304304
return self._hatches[hatch]
305305
name = 'H%d' % len(self._hatches)
306+
linewidth = rcParams['hatch.linewidth']
306307
self._pswriter.write("""\
307308
<< /PatternType 1
308309
/PaintType 2
@@ -313,7 +314,7 @@ def create_hatch(self, hatch):
313314
314315
/PaintProc {
315316
pop
316-
0 setlinewidth
317+
%(linewidth)f setlinewidth
317318
""" % locals())
318319
self._pswriter.write(
319320
self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0),

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def _write_hatches(self):
393393
style=generate_css({
394394
'fill': rgb2hex(stroke),
395395
'stroke': rgb2hex(stroke),
396-
'stroke-width': '1.0',
396+
'stroke-width': six.text_type(rcParams['hatch.linewidth']),
397397
'stroke-linecap': 'butt',
398398
'stroke-linejoin': 'miter'
399399
})

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ patch.facecolor : b
3232
patch.edgecolor : k
3333
patch.antialiased : True # render patches in antialiased (no jaggies)
3434

35+
hatch.linewidth : 1.0
36+
3537
hist.bins : 10
3638

3739
### FONT

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,9 @@ def validate_animation_writer_path(p):
889889
'patch.facecolor': ['#1f77b4', validate_color], # blue (first color in color cycle)
890890
'patch.antialiased': [True, validate_bool], # antialiased (no jaggies)
891891

892+
## hatch props
893+
'hatch.linewidth': [1.0, validate_float],
894+
892895
## Histogram properties
893896
'hist.bins': [10, validate_hist_bins],
894897

matplotlibrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ backend : $TEMPLATE_BACKEND
109109
#patch.edgecolor : black
110110
#patch.antialiased : True # render patches in antialiased (no jaggies)
111111

112+
### HATCHES
113+
#hatch.linewidth : 1.0
114+
112115
### Boxplot
113116
#boxplot.notch : False
114117
#boxplot.vertical : True

src/_backend_agg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
363363
hatch_path_trans_t hatch_path_trans(hatch_path, hatch_trans);
364364
hatch_path_curve_t hatch_path_curve(hatch_path_trans);
365365
hatch_path_stroke_t hatch_path_stroke(hatch_path_curve);
366-
hatch_path_stroke.width(1.0);
366+
hatch_path_stroke.width(points_to_pixels(gc.hatch_linewidth));
367367
hatch_path_stroke.line_cap(agg::square_cap);
368368

369369
// Render the path into the hatch buffer

src/_backend_agg_basic_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class GCAgg
108108
e_snap_mode snap_mode;
109109

110110
py::PathIterator hatchpath;
111+
double hatch_linewidth;
111112

112113
SketchParams sketch;
113114

src/py_converters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ int convert_gcagg(PyObject *pygc, void *gcp)
481481
convert_from_method(pygc, "get_clip_path", &convert_clippath, &gc->clippath) &&
482482
convert_from_method(pygc, "get_snap", &convert_snap, &gc->snap_mode) &&
483483
convert_from_method(pygc, "get_hatch_path", &convert_path, &gc->hatchpath) &&
484+
convert_from_method(pygc, "get_hatch_linewidth", &convert_double, &gc->hatch_linewidth) &&
484485
convert_from_method(pygc, "get_sketch_params", &convert_sketch_params, &gc->sketch))) {
485486
return 0;
486487
}

0 commit comments

Comments
 (0)