|
@@ -129,12 +129,22 @@ def setBarsBW(fig):
|
|
|
patterns = ['0', '///', '---', '|||', '+++', '**', 'oo', '...']
|
|
|
inx = 0
|
|
|
boxes = []
|
|
|
+ # Associate each color with a pattern so as to reuse the patterns
|
|
|
+ color_associations = {}
|
|
|
+ # Find all rectangles in the graph
|
|
|
for ax in fig.get_axes():
|
|
|
for child in ax.get_children():
|
|
|
if isinstance(child, matplotlib.patches.Rectangle):
|
|
|
boxes.append(child)
|
|
|
- # Skip the last rectangle which should be the background
|
|
|
- for box in boxes[:-1]:
|
|
|
- box.set_hatch(patterns[inx])
|
|
|
- inx += 1
|
|
|
- if inx == len(patterns): inx = 0
|
|
|
+ # Skip some rectangles. Only change rectangles that have a color matching ours.
|
|
|
+ for box in boxes:
|
|
|
+ hex_color = matplotlib.colors.to_hex(box.get_facecolor())
|
|
|
+ if hex_color in paper_colors:
|
|
|
+ if hex_color not in color_associations:
|
|
|
+ color_associations[hex_color] = patterns[inx]
|
|
|
+ inx += 1
|
|
|
+ if inx == len(patterns): inx = 0
|
|
|
+
|
|
|
+ box.set_hatch(color_associations[hex_color])
|
|
|
+
|
|
|
+
|