Skip to content

Commit 94aa071

Browse files
authored
Merge pull request #220 from tino-michael/astropy_units
drawing no longer breaks if data contain astropy quantities
2 parents 90480fb + a1cfd17 commit 94aa071

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

matplotlib2tikz/line2d.py

Lines changed: 11 additions & 0 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:

0 commit comments

Comments
 (0)