plt.fill_between() causes AttributeError: 'IdentityTransform' object has no attribute 'copy'
MaxGaukler opened this issue · comments
Since Matplotlib 3.3, plt.fill_between()
causes errors in tikzplotlib:
from matplotlib import pyplot as plt
import tikzplotlib
plt.fill_between([0, 1], [2, 3])
print(tikzplotlib.get_tikz_code())
Traceback (most recent call last):
File "bug.py", line 6, in <module>
print(tikzplotlib.get_tikz_code())
File "/home/user/.local/lib/python3.6/site-packages/tikzplotlib/_save.py", line 207, in get_tikz_code
data, content = _recurse(data, figure)
File "/home/user/.local/lib/python3.6/site-packages/tikzplotlib/_save.py", line 351, in _recurse
data, children_content = _recurse(data, child)
File "/home/user/.local/lib/python3.6/site-packages/tikzplotlib/_save.py", line 376, in _recurse
data, cont = _draw_collection(data, child)
File "/home/user/.local/lib/python3.6/site-packages/tikzplotlib/_save.py", line 323, in _draw_collection
return _patch.draw_patchcollection(data, child)
File "/home/user/.local/lib/python3.6/site-packages/tikzplotlib/_patch.py", line 95, in draw_patchcollection
path = path.transformed(mpl.transforms.Affine2D(t).translate(*off))
File "/home/user/.local/lib/python3.6/site-packages/matplotlib/transforms.py", line 1846, in __init__
self._mtx = matrix.copy()
AttributeError: 'IdentityTransform' object has no attribute 'copy'
The problem is that matplotlib.transforms.Affine2D()
expects a numpy.ndarray
(or at least the docstring claims so):
However, we pass it a matplotlib.transforms.IdentityTransform
:
tikzplotlib/tikzplotlib/_patch.py
Lines 92 to 95 in ddf7ae3
If my diagnosis is correct, then this code would never work at all, which is strange given the fact that this case is covered by unittests: https://codecov.io/gh/nschloe/tikzplotlib/src/07c0f52bf8cb6808271a00d3199e75dedc7d837b/tikzplotlib/_patch.py#L90...97
I am using matplotlib 3.3.0. The error disappears with matplotlib 3.2.0. This may be related to a change in matplotlib: matplotlib/matplotlib@88e40cb#diff-9d3a2ed9922d92407a1b5e9c4862d1d1L1833-L1835
Maybe Affine2D()
was used the wrong way since long ago, but the error only surfaced now?
Your diagnosis seems correct to me. I can confirm that unittests fail right now with matplotlib 3.3 but work well with 3.2.
Fixed now.