File tree Expand file tree Collapse file tree 4 files changed +35
-28
lines changed
Expand file tree Collapse file tree 4 files changed +35
-28
lines changed Original file line number Diff line number Diff line change 88from . import path as mypath
99from . import files
1010
11-
12- def _has_legend (axes ):
13- return axes .get_legend () is not None
14-
15-
16- def _get_legend_text (line ):
17- """Check if line is in legend.
18- """
19- leg = line .axes .get_legend ()
20- if leg is None :
21- return None
22-
23- keys = [l .get_label () for l in leg .get_lines ()]
24- values = [l .get_text () for l in leg .texts ]
25-
26- label = line .get_label ()
27- d = dict (zip (keys , values ))
28- if label in d :
29- return d [label ]
30-
31- return None
11+ from .util import get_legend_text , has_legend
3212
3313
3414def draw_line2d (data , obj ):
@@ -84,8 +64,8 @@ def draw_line2d(data, obj):
8464
8565 # Check if a line is in a legend and forget it if not.
8666 # Fixes <https://github.com/nschloe/matplotlib2tikz/issues/167>.
87- legend_text = _get_legend_text (obj )
88- if legend_text is None and _has_legend (obj .axes ):
67+ legend_text = get_legend_text (obj )
68+ if legend_text is None and has_legend (obj .axes ):
8969 addplot_options .append ("forget plot" )
9070
9171 # process options
Original file line number Diff line number Diff line change 66from . import color
77from .axes import _mpl_cmap2pgf_cmap
88
9+ from .util import has_legend , get_legend_text
10+
911
1012def draw_path (data , path , draw_options = None , simplify = None ):
1113 """Adds code for drawing an ordinary path in PGFPlots (TikZ).
@@ -159,10 +161,11 @@ def draw_pathcollection(data, obj):
159161
160162 if obj .get_cmap ():
161163 mycolormap , is_custom_cmap = _mpl_cmap2pgf_cmap (obj .get_cmap (), data )
162- if is_custom_cmap :
163- draw_options .append ("colormap=" + mycolormap )
164- else :
165- draw_options .append ("colormap/" + mycolormap )
164+ draw_options .append ("colormap" + ("=" if is_custom_cmap else "/" ) + mycolormap )
165+
166+ legend_text = get_legend_text (obj )
167+ if legend_text is None and has_legend (obj .axes ):
168+ draw_options .append ("forget plot" )
166169
167170 for path in obj .get_paths ():
168171 if is_contour :
Original file line number Diff line number Diff line change @@ -224,7 +224,7 @@ def get_tikz_code(
224224\\ usepackage{{pgfplots}}
225225\\ usepgfplotslibrary{{groupplots}}
226226\\ pgfplotsset{{compat=newest}}
227- \\ DeclareUnicodeCharacter{{2212}}{{- }}
227+ \\ DeclareUnicodeCharacter{{2212}}{{− }}
228228\\ begin{{document}}
229229{}
230230\\ end{{document}}""" .format (
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ #
3+
4+
5+ def has_legend (axes ):
6+ return axes .get_legend () is not None
7+
8+
9+ def get_legend_text (obj ):
10+ """Check if line is in legend.
11+ """
12+ leg = obj .axes .get_legend ()
13+ if leg is None :
14+ return None
15+
16+ keys = [l .get_label () for l in leg .legendHandles if l is not None ]
17+ values = [l .get_text () for l in leg .texts ]
18+
19+ label = obj .get_label ()
20+ d = dict (zip (keys , values ))
21+ if label in d :
22+ return d [label ]
23+
24+ return None
You can’t perform that action at this time.
0 commit comments