Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Labels
Description
Documentation Link
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html
Problem
The explanation forlabels
says it accepts either sequence of strings or Texts:
However, it's also possible to pass as a parameter e.g.list
ofints
orfloats
or similar and the method works too.
I think this should be reflected in the doc.
importrandomimportmatplotlib.pyplotaspltx=sorted(random.sample(range(15),5))y=sorted(random.sample(range(10),5))fig,ax=plt.subplots(figsize=(10,6))ax.plot(x,y,"o-")ax.set_xticks(x)ax.set_xticklabels(x)# x is `list` of INTs, not stringsax.grid(axis="x")
Gives this, without any problems:
Or if you generate list of floats:
x_labels= [random.random()for_inrange(len(x))]
And then update the tick labels:
ax.set_xticklabels(x_labels)# x is `list` of FLOATs, not strings
Suggested improvement
Update the description so it's clear numeric arrays can be passed on as a parameter.