Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tikzplotlib module throws attribute error: module 'webcolors' has no attribute 'CSS3_HEX_TO_NAMES'

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.

like image 783
user25742608 Avatar asked Oct 29 '25 15:10

user25742608


1 Answers

tikzplotlib is no longer regularly maintained, so it may be best to clone/fork it and update a local copy.

The offending line is for h, name in webcolors.CSS3_HEX_TO_NAMES.items(): in /src/tikzplotlib/_color.py. For webcolors 24.8.0, you can replace this line with

for name in webcolors.names('css3'):
    h = webcolors.name_to_hex(name)
like image 109
Quiggin Avatar answered Nov 01 '25 05:11

Quiggin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!