Skip to content

Commit 72a3987

Browse files
committed
methods in _patch now uses decorator
1 parent 2e84295 commit 72a3987

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

tikzplotlib/_patch.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ def draw_patch(data, obj):
2424
elif isinstance(obj, mpl.patches.Ellipse):
2525
# ellipse specialization
2626
return _draw_ellipse(data, obj, draw_options)
27+
else:
28+
# regular patch
29+
return _draw_polygon(data, obj, draw_options)
2730

28-
# regular patch
29-
data, path_command, _, _ = mypath.draw_path(
30-
data, obj.get_path(), draw_options=draw_options
31-
)
32-
return data, path_command
3331

3432
def _is_in_legend(obj):
3533
label = obj.get_label()
@@ -112,7 +110,14 @@ def draw_patchcollection(data, obj):
112110

113111
return data, content
114112

113+
@legendimage
114+
def _draw_polygon(data, obj, draw_options):
115+
data, content, _, is_area = mypath.draw_path(
116+
data, obj.get_path(), draw_options=draw_options
117+
)
118+
legend_type = "area legend" if is_area else "line legend"
115119

120+
return data, content, legend_type
116121

117122

118123
def _draw_rectangle(data, obj, draw_options):
@@ -158,6 +163,7 @@ def _draw_rectangle(data, obj, draw_options):
158163
return data, cont
159164

160165

166+
@legendimage
161167
def _draw_ellipse(data, obj, draw_options):
162168
"""Return the PGFPlots code for ellipses.
163169
"""
@@ -180,17 +186,19 @@ def _draw_ellipse(data, obj, draw_options):
180186
+ ff
181187
+ " and "
182188
+ ff
183-
+ ");\n"
189+
+ ");"
184190
).format(",".join(draw_options), x, y, 0.5 * obj.width, 0.5 * obj.height)
185-
return data, cont
186191

192+
return data, cont, "area legend"
187193

194+
195+
@legendimage
188196
def _draw_circle(data, obj, draw_options):
189197
"""Return the PGFPlots code for circles.
190198
"""
191199
x, y = obj.center
192200
ff = data["float format"]
193-
cont = ("\\draw[{}] (axis cs:" + ff + "," + ff + ") circle (" + ff + ");\n").format(
201+
cont = ("\\draw[{}] (axis cs:" + ff + "," + ff + ") circle (" + ff + ");").format(
194202
",".join(draw_options), x, y, obj.get_radius()
195203
)
196-
return data, cont
204+
return data, cont, "area legend"

0 commit comments

Comments
 (0)