Home > Blockchain >  Matplotlib / df.plot(): set custom integer xticks for spectrum of floats
Matplotlib / df.plot(): set custom integer xticks for spectrum of floats

Time:05-12

Edit / Solved: I forgot to check the type of x axis and it was still a string. Check my answer for solution.

Edit: please note that I have more values in x axis (and in floats) that I want ticks (integers), which makes usual solution not work (like enter image description here

and ax.set_xticks(range(0, 100, 2)) and similar give me:

enter image description here

CodePudding user response:

You can try:

# set the x tick positions
ax.set_xticks(list(range(0, 101, 2)))

# now set the xtick labels at those positions
ax.set_xticklabels([f"{int(xval)}" for xval in range(0, 101, 2)])

Note that the range goes to 101, so that it includes the number 100.

CodePudding user response:

Thank you all for taking time for answer, but I'm just not very smart apparently. I forgot to check the type, and instead of floats, I have had strings

df = df.astype('float64')
df.index = df.index.astype('float64')
  • Related