Skip to content

Commit 14d3463

Browse files
committed
Support paths with datetime x-axis (#328)
1 parent d7cfc31 commit 14d3463

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tikzplotlib/_path.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import matplotlib as mpl
22
import numpy
33
from matplotlib.markers import MarkerStyle
4+
from matplotlib.dates import num2date, DateConverter
45

56
from . import _color
67
from ._axes import _mpl_cmap2pgf_cmap
@@ -22,10 +23,14 @@ def draw_path(data, path, draw_options=None, simplify=None):
2223
):
2324
return data, "", None, False
2425

26+
x_is_date = isinstance(data["current mpl axes obj"].xaxis.converter, DateConverter)
2527
nodes = []
2628
ff = data["float format"]
29+
xformat = "{}" if x_is_date else ff
2730
prev = None
2831
for vert, code in path.iter_segments(simplify=simplify):
32+
if x_is_date:
33+
vert = [num2date(vert[0]), vert[1]]
2934
# nschloe, Oct 2, 2015:
3035
# The transform call yields warnings and it is unclear why. Perhaps
3136
# the input data is not suitable? Anyhow, this should not happen.
@@ -38,9 +43,9 @@ def draw_path(data, path, draw_options=None, simplify=None):
3843
# if code == mpl.path.Path.STOP: pass
3944
is_area = False
4045
if code == mpl.path.Path.MOVETO:
41-
nodes.append(("(axis cs:" + ff + "," + ff + ")").format(*vert))
46+
nodes.append(("(axis cs:" + xformat + "," + ff + ")").format(*vert))
4247
elif code == mpl.path.Path.LINETO:
43-
nodes.append(("--(axis cs:" + ff + "," + ff + ")").format(*vert))
48+
nodes.append(("--(axis cs:" + xformat + "," + ff + ")").format(*vert))
4449
elif code == mpl.path.Path.CURVE3:
4550
# Quadratic Bezier curves aren't natively supported in TikZ, but
4651
# can be emulated as cubic Beziers.

0 commit comments

Comments
 (0)