I am trying to convert some numbers represented as strings but I get an error!
Here is my code
import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(-np.pi*2, np.pi*2, 200)
b = np.cos(a)
fig, ax = plt.subplots()
ax.plot(a, b)
fig.canvas.draw()
labels = [item.get_text() for item in ax.get_xticklabels()]
labels = [float(label) for label in labels]
float(labels[-1]) # this works
error : labels = [float(label) for label in labels] ValueError: could not convert string to float: '−8'
labels, in this case, can be generated as [str(i) for i in range(-8, 9, 2)] which I can convert its items to float but not the text of the label retrieved from matplotlib!
I believe the issue is with the - sign.
since when i check
'-8' in labels gives False
but '8' in labels gives True