Skip to content

Commit 5dd1a27

Browse files
authored
Merge pull request #168 from spott/patch-1
Lines that aren't in the legend should have their colors skipped
2 parents a00e697 + f7f4893 commit 5dd1a27

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

matplotlib2tikz/line2d.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
from . import color as mycol
88
from . import path as mypath
99

10+
def get_legend_label_(line):
11+
'''Check if line is in legend
12+
'''
13+
14+
label = line.get_label()
15+
try:
16+
ax = line.axes
17+
leg = ax.get_legend()
18+
return label in [l.get_label() for l in leg.get_lines()]
19+
except AttributeError:
20+
return None
1021

1122
def draw_line2d(data, obj):
1223
'''Returns the PGFPlots code for an Line2D environment.
@@ -97,6 +108,11 @@ def draw_line2d(data, obj):
97108
if marker and not show_line:
98109
addplot_options.append('only marks')
99110

111+
# Check if a line is not in a legend and forget it if so,
112+
# fixes bug #167:
113+
if not get_legend_label_(obj):
114+
addplot_options.append("forget plot")
115+
100116
# process options
101117
content.append('\\addplot ')
102118
if addplot_options:

test/test_legend_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def plot():
2424

2525
def test():
2626
phash = helpers.Phash(plot())
27-
assert phash.phash == 'eb785e0aaed6c190', phash.get_details()
27+
assert phash.phash == 'eb785e0aaed68194', phash.get_details()
2828
return
2929

3030

0 commit comments

Comments
 (0)