Skip to content

Commit 6f5375c

Browse files
committed
Add support for Bezier paths with datetime x-axis
1 parent 14d3463 commit 6f5375c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

tikzplotlib/_path.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ def draw_path(data, path, draw_options=None, simplify=None):
2929
xformat = "{}" if x_is_date else ff
3030
prev = None
3131
for vert, code in path.iter_segments(simplify=simplify):
32-
if x_is_date:
33-
vert = [num2date(vert[0]), vert[1]]
3432
# nschloe, Oct 2, 2015:
3533
# The transform call yields warnings and it is unclear why. Perhaps
3634
# the input data is not suitable? Anyhow, this should not happen.
@@ -43,8 +41,12 @@ def draw_path(data, path, draw_options=None, simplify=None):
4341
# if code == mpl.path.Path.STOP: pass
4442
is_area = False
4543
if code == mpl.path.Path.MOVETO:
44+
if x_is_date:
45+
vert = [num2date(vert[0]), vert[1]]
4646
nodes.append(("(axis cs:" + xformat + "," + ff + ")").format(*vert))
4747
elif code == mpl.path.Path.LINETO:
48+
if x_is_date:
49+
vert = [num2date(vert[0]), vert[1]]
4850
nodes.append(("--(axis cs:" + xformat + "," + ff + ")").format(*vert))
4951
elif code == mpl.path.Path.CURVE3:
5052
# Quadratic Bezier curves aren't natively supported in TikZ, but
@@ -68,41 +70,54 @@ def draw_path(data, path, draw_options=None, simplify=None):
6870
Q1 = 1.0 / 3.0 * prev + 2.0 / 3.0 * vert[0:2]
6971
Q2 = 2.0 / 3.0 * vert[0:2] + 1.0 / 3.0 * vert[2:4]
7072
Q3 = vert[2:4]
73+
if x_is_date:
74+
Q1 = [num2date(Q1[0]), Q1[1]]
75+
Q2 = [num2date(Q2[0]), Q2[1]]
76+
Q3 = [num2date(Q3[0]), Q3[1]]
7177
nodes.append(
7278
(
7379
".. controls (axis cs:"
74-
+ ff
80+
+ xformat
7581
+ ","
7682
+ ff
7783
+ ") "
7884
+ "and (axis cs:"
79-
+ ff
85+
+ xformat
8086
+ ","
8187
+ ff
8288
+ ") "
8389
+ ".. (axis cs:"
84-
+ ff
90+
+ xformat
8591
+ ","
8692
+ ff
8793
+ ")"
8894
).format(Q1[0], Q1[1], Q2[0], Q2[1], Q3[0], Q3[1])
8995
)
9096
elif code == mpl.path.Path.CURVE4:
9197
# Cubic Bezier curves.
98+
if x_is_date:
99+
vert = [
100+
num2date(vert[0]),
101+
vert[1],
102+
num2date(vert[2]),
103+
vert[3],
104+
num2date(vert[4]),
105+
vert[5],
106+
]
92107
nodes.append(
93108
(
94109
".. controls (axis cs:"
95-
+ ff
110+
+ xformat
96111
+ ","
97112
+ ff
98113
+ ") "
99114
+ "and (axis cs:"
100-
+ ff
115+
+ xformat
101116
+ ","
102117
+ ff
103118
+ ") "
104119
+ ".. (axis cs:"
105-
+ ff
120+
+ xformat
106121
+ ","
107122
+ ff
108123
+ ")"

0 commit comments

Comments
 (0)