skip to Main Content

I would like to convert matplotlib figures to PGFPlots/Tikz figures while using the module tikzplotlib:

import matplotlib.pyplot as plt
import numpy as np
import tikzplotlib

x = np.linspace(0, 2*np.pi, 51)
y = np.sin(x)

plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")

tikzplotlib.save('test.tex')

When I run this code, I get an attribute error:

AttributeError: module 'webcolors' has no attribute 'CSS3_HEX_TO_NAMES'

The documentations of tikzplotlib and webcolors did not give me an idea to solve this.

I have found related questions(1, 2) to the described attribute error from the webcolors module without a solution for me.

Is someone able to reproduce this error or knows a solution for this?

I am working with python 3.9.5, webcolors 24.6.0 and tikzplotlib 0.10.1 in Visual Studio Code Version 1.90.2 on Windows 11.

2

Answers


  1. Chosen as BEST ANSWER

    Solved:

    The module webcolors had recent changes and the attributes for the mapping of color names/values is no longer publically accessible. Since tikzplotlib has not been updated to this changes, an older version (e.g. version 1.13) of webcolors must be used.


  2. thank you! i solved it. but why? why the latest version doesn’t have a useful function?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search