Skip to content

Commit b242628

Browse files
committed
Added function to check if line is in legend, then use *that* to plot, or not plot, a legend entry for a line
1 parent e5b4798 commit b242628

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

matplotlib2tikz/line2d.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
from . import color as mycol
44
from . import path as mypath
55

6+
def get_legend_label_(line):
7+
'''Check if line is in legend
8+
'''
9+
10+
label = line.get_label()
11+
try:
12+
ax = line.axes
13+
leg = ax.get_legend()
14+
return label in [l.get_label() for l in leg.get_lines()]
15+
except:
16+
return None
617

718
def draw_line2d(data, obj):
819
'''Returns the PGFPlots code for an Line2D environment.
@@ -92,7 +103,7 @@ def draw_line2d(data, obj):
92103

93104
# Check if a line is not in a legend and forget it if so,
94105
# fixes bug #167:
95-
if obj.get_label().startswith("_line"):
106+
if not get_legend_label_(obj):
96107
addplot_options.append("forget plot")
97108

98109
# process options

0 commit comments

Comments
 (0)