Skip to content

Commit 926a2d7

Browse files
author
Tino Michael
committed
moved the stripping further up
1 parent 6a5c94d commit 926a2d7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

matplotlib2tikz/line2d.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ def draw_line2d(data, obj):
128128
# xdata, ydata = _transform_to_data_coordinates(obj, *obj.get_data())
129129
xdata, ydata = obj.get_data()
130130

131+
# matplotlib allows plotting of data containing `astropy.units`, but they will
132+
# break the formatted string here. Try to strip the units from the data.
133+
try:
134+
xdata = xdata.value
135+
except AttributeError:
136+
pass
137+
try:
138+
ydata = ydata.value
139+
except AttributeError:
140+
pass
141+
131142
try:
132143
has_mask = ydata.mask.any()
133144
except AttributeError:
@@ -144,16 +155,6 @@ def draw_line2d(data, obj):
144155
else:
145156
content.append('%.15g %.15g\n' % (x, y))
146157
else:
147-
# matplotlib allows plotting of data containing `astropy.units`, but they will
148-
# break the formatted string here. Try to strip the units from the data.
149-
try:
150-
xdata = xdata.value
151-
except AttributeError:
152-
pass
153-
try:
154-
ydata = ydata.value
155-
except AttributeError:
156-
pass
157158
for (x, y) in zip(xdata, ydata):
158159
content.append('%.15g %.15g\n' % (x, y))
159160
content.append('};\n')

0 commit comments

Comments
 (0)