nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dashed Lines not supported since mpl 3.6.2

michi7x7 opened this issue · comments

Exporting a dashed line

import tikzplotlib
import matplotlib.pyplot as plt

plt.figure()
plt.plot([0, 1], [0, 1], 'k--')
tikzplotlib.get_tikz_code()

results in an error:

AttributeError: 'Line2D' object has no attribute '_us_dashSeq'

This happens because matplotlib v3.6.2 (commit-link) changed the way it handles the dash-patterns in its internal code.

A quick fix can be implemented by Monkey-patching MPL:

from matplotlib.lines import Line2D
from matplotlib.legend import Legend
Line2D._us_dashSeq    = property(lambda self: self._dash_pattern[1])
Line2D._us_dashOffset = property(lambda self: self._dash_pattern[0])
Legend._ncol = property(lambda self: self._ncols)

The Legend-patch fixes #564

Had the same issue.