6
6
from ._axes import _mpl_cmap2pgf_cmap
7
7
from ._markers import _mpl_marker2pgfp_marker
8
8
from ._util import get_legend_text , has_legend
9
+ from ._hatches import _mpl_hatch2pgfp_pattern
9
10
10
11
11
12
def draw_path (data , path , draw_options = None , simplify = None ):
@@ -233,7 +234,7 @@ def draw_pathcollection(data, obj):
233
234
return data , content
234
235
235
236
236
- def get_draw_options (data , obj , ec , fc , ls , lw ):
237
+ def get_draw_options (data , obj , ec , fc , ls , lw , hatch = None ):
237
238
"""Get the draw options for a given (patch) object.
238
239
Get the draw options for a given (patch) object.
239
240
Input:
@@ -243,6 +244,7 @@ def get_draw_options(data, obj, ec, fc, ls, lw):
243
244
fc - face color
244
245
ls - linestyle
245
246
lw - linewidth
247
+ hatch=None - hatch, i.e., pattern within closed path
246
248
Output:
247
249
draw_options - list, to be ",".join(draw_options) to produce the
248
250
draw options passed to PGF
@@ -284,6 +286,35 @@ def get_draw_options(data, obj, ec, fc, ls, lw):
284
286
if ls_ is not None and ls_ != "solid" :
285
287
draw_options .append (ls_ )
286
288
289
+ if hatch is not None :
290
+ # In matplotlib hatches are rendered with edge color and linewidth
291
+ # In PGFPlots patterns are rendered in 'pattern color' which defaults to
292
+ # black and according to opacity fill.
293
+ # No 'pattern line width' option exist.
294
+ # This can be achieved with custom patterns, see _hatches.py
295
+
296
+ # There exist an obj.get_hatch_color() method in the mpl API,
297
+ # but it seems to be unused
298
+ try :
299
+ hc = obj ._hatch_color
300
+ except AttributeError : # Fallback to edge color
301
+ if ec is None or ec_rgba [3 ] == 0.0 :
302
+ # Assuming that a hatch marker indicates that hatches are wanted, also
303
+ # when the edge color is (0, 0, 0, 0), i.e., the edge is invisible
304
+ h_col , h_rgba = "black" , numpy .array ([0 , 0 , 0 , 1 ])
305
+ else :
306
+ h_col , h_rgba = ec_col , ec_rgba
307
+ else :
308
+ data , h_col , h_rgba = _color .mpl_color2xcolor (data , hc )
309
+ finally :
310
+ if h_rgba [3 ] > 0 :
311
+ data , pattern = _mpl_hatch2pgfp_pattern (data , hatch , h_col , h_rgba )
312
+ if ec_rgba [3 ] == 0.0 :
313
+ # 'draw=none' must be specified for the border to be omitted
314
+ # when a pattern is drawn using \draw.
315
+ draw_options .append ("draw={}" .format (ec_col ))
316
+ draw_options += pattern
317
+
287
318
return data , draw_options
288
319
289
320
0 commit comments