nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.
MIT License
2.41k stars 215 forks source link

Matplotlib version >> 3.6.2, gives AttributeError: 'Line2D' object has no attribute '_us_dashSeq' #580

Open VijayN10 opened 1 year ago

VijayN10 commented 1 year ago

I was unable to save the plot as a TikZ file after upgrading to latest version of matplotlib. It was giving an error of AttributeError: 'Line2D' object has no attribute '_us_dashSeq'

For plotting, I was using the following code. The error was identified with line style and markevery function.

line_styles = ['-', '--', '-.', ':', '-']
markers = ['o', 's', '^', '*', 'd']

plt.plot(x_sph_dp1, y_sph_dp1, label='dp = 0.2', color='red', linestyle=line_styles[0], marker=markers[0], linewidth=2, markevery=(0, 10))
plt.plot(x_sph_dp2, y_sph_dp2, label='dp = 0.1', color='orange', linestyle=line_styles[1], marker=markers[1], linewidth=2, markevery=(0, 10))
plt.plot(x_sph_dp2, y_sph_dp2, label='dp = 0.05', color='orange', linestyle=line_styles[2], marker=markers[2], linewidth=2, markevery=(0, 10))
plt.plot(x_exp, y_exp, label='Experiment', color='blue', linestyle=line_styles[3], marker=markers[3], linewidth=2, markevery=(0, 2))
plt.plot(x_vof, y_vof, label='VOF', color='green', linestyle=line_styles[4], marker=markers[4], linewidth=2, markevery=(0, 2))
VijayN10 commented 1 year ago

After downgrading to Matplotlib version 3.5.1, the problem has been resolved.

But is there any other way? Please let me know. Thank you..

FriedrichFroebel commented 1 year ago

This has been changed in matplotlib version 3.6.0 and needs a corresponding fix/PR.

Upstream change: https://github.com/matplotlib/matplotlib/pull/21050

nyngwang commented 1 year ago

@FriedrichFroebel Is there any workaround for this?

FriedrichFroebel commented 1 year ago

I have not tested this, but replacing https://github.com/nschloe/tikzplotlib/blob/450712b4014799ec5f151f234df84335c90f4b9d/src/tikzplotlib/_path.py#L472-L473 with

        dashOffset, dashSeq = line._unscaled_dash_pattern

might work given https://github.com/matplotlib/matplotlib/pull/21050/files#diff-be677869a88f58790f2387fb2ac0ae12e2e9610d7c7096e25d3087d5ed9645c8L1133-R1121

sbiser commented 1 year ago

Solution presented by @FriedrichFroebel works just fine, I've just tested it successfully.

VijayN10 commented 1 year ago

Thanks @FriedrichFroebel , its working for me as well! I hope it will be incorporated in next release. I am closing this issue now.

FriedrichFroebel commented 1 year ago

@VijayN10 I do not think that it really makes sense to close this issue while there is no upstream solution for it. For now, there is no corresponding PR to ensure that once this library is finally receiving some more maintenance again this will have an official fix.

VijayN10 commented 1 year ago

@nschloe , @FriedrichFroebel - Okay. Thanks.

marko-pi commented 6 months ago

Since it is next to impossible to install matplotlib <=3.6, the tikzplotlib package is useless. It would only be fair to remove it from the package list on PyPI.

FriedrichFroebel commented 6 months ago

I do not consider it impossible to install matplotlib<3.6.0 - at least a rather basic Ubuntu 22.04 installation (still supported until 2027) does not seem to have any issues with it. Issues might arise with further libraries requiring more recent matplotlib versions, but matplotlib core functionality should (in theory) not really be affected at all if your own code is compatible enough. (I do not like the tikzplotlib situation either, but I hate reading false claims.) For the same reason, removing the package from PyPI is even more uncommon/worse as it breaks tikzplotlib for everyone and there surely are tons of PyPI packages which have been unmaintained for sometimes more than 10 years.

marko-pi commented 6 months ago

I tried to install matplotlib 3.5 on my Windows system with python.org distribution. After overcoming several hurdles and losing several hours, I finally failed. Well, now I have gone back to exporting PDFs and loading them into Latex files.

I started using tikzplotlib about two years ago and regret that decision because of all the extra problems. I am not an expert on Python packages and perhaps they should all continue to be available, but it would be fair if potential users were warned of the pitfalls that can occur when using tikzplotlib.