diff --git a/doc/users/whats_new/style_changes.rst b/doc/users/whats_new/style_changes.rst index c1152e6bba0d..e5a9a11e110a 100644 --- a/doc/users/whats_new/style_changes.rst +++ b/doc/users/whats_new/style_changes.rst @@ -35,6 +35,18 @@ Plots the rcParam ``lines.markersize`` so it is consistent with ``plot(X, Y, 'o')``. The old value was 20, and the new value is 36 (6^2). +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: + + - PDF: 0.1 pt + - SVG: 1.0 pt + - PS: 1 px + - Agg: 1 px + Plot layout ``````````` diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 08b54b503b10..1bee2fe7c5b8 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -792,6 +792,7 @@ def __init__(self): self._linewidth = 1 self._rgb = (0.0, 0.0, 0.0, 1.0) self._hatch = None + self._hatch_linewidth = rcParams['hatch.linewidth'] self._url = None self._gid = None self._snap = None @@ -1111,6 +1112,12 @@ def get_hatch_path(self, density=6.0): return None return Path.hatch(self._hatch, density) + def get_hatch_linewidth(self): + """ + Gets the linewidth to use for hatching. + """ + return self._hatch_linewidth + def get_sketch_params(self): """ Returns the sketch parameters for the artist. diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 618f9be8f2ea..8bbe991bd1a1 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1182,7 +1182,7 @@ def writeHatches(self): 0, 0, sidelen, sidelen, Op.rectangle, Op.fill) - self.output(0.1, Op.setlinewidth) + self.output(rcParams['hatch.linewidth'], Op.setlinewidth) # TODO: We could make this dpi-dependent, but that would be # an API change diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 50bcaa3a320f..2f8ffaeaf659 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -303,6 +303,7 @@ def create_hatch(self, hatch): if hatch in self._hatches: return self._hatches[hatch] name = 'H%d' % len(self._hatches) + linewidth = rcParams['hatch.linewidth'] self._pswriter.write("""\ << /PatternType 1 /PaintType 2 @@ -313,7 +314,7 @@ def create_hatch(self, hatch): /PaintProc { pop - 0 setlinewidth + %(linewidth)f setlinewidth """ % locals()) self._pswriter.write( self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0), diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index eb789622402e..f8af96043211 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -393,7 +393,7 @@ def _write_hatches(self): style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), - 'stroke-width': '1.0', + 'stroke-width': six.text_type(rcParams['hatch.linewidth']), 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 4216dc18d20e..2ba86163b8cb 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -32,6 +32,8 @@ patch.facecolor : b patch.edgecolor : k patch.antialiased : True # render patches in antialiased (no jaggies) +hatch.linewidth : 1.0 + hist.bins : 10 ### FONT diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a7c56be6f256..2a8e80aafa9b 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -870,6 +870,9 @@ def validate_animation_writer_path(p): 'patch.facecolor': ['#1f77b4', validate_color], # blue (first color in color cycle) 'patch.antialiased': [True, validate_bool], # antialiased (no jaggies) + ## hatch props + 'hatch.linewidth': [1.0, validate_float], + ## Histogram properties 'hist.bins': [10, validate_hist_bins], diff --git a/lib/matplotlib/tests/baseline_images/test_artist/clip_path_clipping.png b/lib/matplotlib/tests/baseline_images/test_artist/clip_path_clipping.png index 407cd7b72849..06189ec491f8 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_artist/clip_path_clipping.png and b/lib/matplotlib/tests/baseline_images/test_artist/clip_path_clipping.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png index fdbbdb075851..d72a331fabc9 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png and b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png index b8a6c34709f7..a324554de74c 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png and b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_colorbar/double_cbar.png b/lib/matplotlib/tests/baseline_images/test_colorbar/double_cbar.png index ff2c50eb405c..fdf399c1a92d 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_colorbar/double_cbar.png and b/lib/matplotlib/tests/baseline_images/test_colorbar/double_cbar.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_basic.png b/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_basic.png index efecd2750d03..7b6e14949e23 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_basic.png and b/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_basic.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_ignore.png b/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_ignore.png index 3aee62f56b26..a6b3fc0d80e7 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_ignore.png and b/lib/matplotlib/tests/baseline_images/test_cycles/fill_cycle_ignore.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_patheffects/patheffect3.png b/lib/matplotlib/tests/baseline_images/test_patheffects/patheffect3.png index 91cee1a16657..253fb029118c 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_patheffects/patheffect3.png and b/lib/matplotlib/tests/baseline_images/test_patheffects/patheffect3.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_simplification/hatch_simplify.png b/lib/matplotlib/tests/baseline_images/test_simplification/hatch_simplify.png index 7ccbcaec576c..b95fb059f7fb 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_simplification/hatch_simplify.png and b/lib/matplotlib/tests/baseline_images/test_simplification/hatch_simplify.png differ diff --git a/matplotlibrc.template b/matplotlibrc.template index ed220657175d..6f2a46c4619b 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -109,6 +109,9 @@ backend : $TEMPLATE_BACKEND #patch.edgecolor : black #patch.antialiased : True # render patches in antialiased (no jaggies) +### HATCHES +#hatch.linewidth : 1.0 + ### Boxplot #boxplot.notch : False #boxplot.vertical : True diff --git a/src/_backend_agg.h b/src/_backend_agg.h index 5885dfe3007a..01574f28f3c8 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -363,7 +363,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face, hatch_path_trans_t hatch_path_trans(hatch_path, hatch_trans); hatch_path_curve_t hatch_path_curve(hatch_path_trans); hatch_path_stroke_t hatch_path_stroke(hatch_path_curve); - hatch_path_stroke.width(1.0); + hatch_path_stroke.width(points_to_pixels(gc.hatch_linewidth)); hatch_path_stroke.line_cap(agg::square_cap); // Render the path into the hatch buffer diff --git a/src/_backend_agg_basic_types.h b/src/_backend_agg_basic_types.h index c19b259eaa8c..243d5368ea2e 100644 --- a/src/_backend_agg_basic_types.h +++ b/src/_backend_agg_basic_types.h @@ -108,6 +108,7 @@ class GCAgg e_snap_mode snap_mode; py::PathIterator hatchpath; + double hatch_linewidth; SketchParams sketch; diff --git a/src/py_converters.cpp b/src/py_converters.cpp index 631763bbc37a..175c9a33da06 100644 --- a/src/py_converters.cpp +++ b/src/py_converters.cpp @@ -481,6 +481,7 @@ int convert_gcagg(PyObject *pygc, void *gcp) convert_from_method(pygc, "get_clip_path", &convert_clippath, &gc->clippath) && convert_from_method(pygc, "get_snap", &convert_snap, &gc->snap_mode) && convert_from_method(pygc, "get_hatch_path", &convert_path, &gc->hatchpath) && + convert_from_method(pygc, "get_hatch_linewidth", &convert_double, &gc->hatch_linewidth) && convert_from_method(pygc, "get_sketch_params", &convert_sketch_params, &gc->sketch))) { return 0; }