0

I'm trying to plot a graph from a dataframe stat with labels as individual letters on the x-axis, that are in the index of stat. But instead of ALL letters, only a few are shown to me, although there is enough space on the x- axis for everyone. I tried, several ways:

xticks = sorted(stat.index.values) #array with separated letters
stat.plot(xticks=xticks)

I got numbers instead of letters.

or

ax = stat.plot()
ax.set_xticks(xticks)

matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ['"', ')', ',', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'e', 'o', 'q', '»', 'а', 'б', 'в', 'г', 'д', 'е', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'х', 'ц', 'ч', 'ш', 'ы', 'ь', 'я', '№'

or

ax = stat.plot()
ax.set_xticklabels(xticks)

ValueError: The number of FixedLocator locations (7), usually from a call to set_ticks, does not match the number of ticklabels (46).

or

fig, ax = plt.subplots(1, 1)
locator = matplotlib.ticker.FixedLocator(xticks)
ax.xaxis.set_major_locator(locator)
ax.grid()
stat.plot(ax=ax)

The plot box turns completely white without any data.

Nothing works. How can I do this simple task?

  • If your variable `xticks` contains labels, you can do `ax.set_xticks([i for i in range(len(xticks))]); ax.set_xticklabels(xticks)`. Note that your naming is somewhat confusing. The parameter of `ax.set_xticks(...)` need to be a list or array of numeric positions. – JohanC Jun 29 '21 at 11:09
  • Finally I use this: print(tabulate(stat, headers='keys', tablefmt='psql')) – Aleksey.Stack Jun 29 '21 at 11:42

0 Answers0