Skip to content

Commit 20f3d0a

Browse files
committed
Respect matplotlib path codes
1 parent c602916 commit 20f3d0a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tikzplotlib/_path.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,20 @@ def draw_pathcollection(data, obj):
250250
for path in obj.get_paths():
251251
if is_contour:
252252
dd = path.vertices
253-
dd_strings = np.array([[fmt.format(val) for val in row] for row in dd])
253+
# https://matplotlib.org/stable/api/path_api.html
254+
codes = (
255+
path.codes
256+
if path.codes is not None
257+
else np.array([1] + [2] * (len(dd) - 1))
258+
)
259+
dd_strings = []
260+
for row, code in zip(dd, codes):
261+
if code == 1: # MOVETO
262+
dd_strings += [
263+
[]
264+
] # Inserts a newline to trigger "move to" in pgfplots
265+
dd_strings += [[fmt.format(val) for val in row]]
266+
dd_strings = np.array(dd_strings[1:])
254267

255268
if len(obj.get_sizes()) == len(dd):
256269
# See Pgfplots manual, chapter 4.25.

0 commit comments

Comments
 (0)