matplotlib

How to circumvent ImportError when invoking tikzplotlib?


Invoking

import tikzplotlib

gives

ImportError: cannot import name 'common_texification' from 'matplotlib.backends.backend_pgf' (C:\Users\XXXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\matplotlib\backends\backend_pgf.py)

Can someone tell me what is going on?


Solution

  • I faced the same issue along with some other problems due to the development of tikzplotlib being stalled.

    I forked the tikzplotlib and created a new Python library out of it in which I fixed the most prominent errors (based on solutions provided by others, so thank them). You can find it here: https://github.com/ErwindeGelder/matplot2tikz

    The problem with tikzplotlib is that pull requests are only accepted by the owner, so the development is dependent on a single person. My idea with the matplot2tikz library is to also provide others the rights to approve pull requests (since I am not skilled enough to fix all issues). Hopefully, in that way, we can keep the library up to date or even improve it (there are still a lot of issues).

    In you Python code, just replace

    from tikzplotlib import save
    

    by

    from matplot2tikz import save
    

    and your code hopefully works (at least no import errors I believe).