Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable float numbers in matplotlib [duplicate]

I am making a bot which tracks discord server stats and makes a graph of them.

While making the bot, I faced a problem. The bot shows floating point numbers in the graph which are not supposed to be there.

Graph

Is it possible to disable the float numbers and show only 12, 13, 14 instead of 12, 12.25, 12.50, etc?

like image 776
Delta888 Avatar asked Oct 29 '25 04:10

Delta888


1 Answers

Answer

I suppose your data are in a y list. In this case you can use ax.set_yticks() as here:

yticks = range(min(y), max(y) + 1)
ax.set_yticks(yticks)

Code

import matplotlib.pyplot as plt
plt.style.use('dark_background')

x = ['14.09', '15.09', '16.09', '17.09', '18.09']
y = [12, 13, 13, 14, 14]

fig, ax = plt.subplots()

ax.plot(x, y, color = 'green', linestyle = '-', marker = 'o', markerfacecolor = 'red')
ax.set_facecolor('white')
ax.set_ylabel('Member count')
ax.set_title("Member count for 'СПГ'")
plt.setp(ax.xaxis.get_majorticklabels(), rotation = 90)

yticks = range(min(y), max(y) + 1)
ax.set_yticks(yticks)

plt.show()

Output

enter image description here

like image 105
Zephyr Avatar answered Oct 30 '25 22:10

Zephyr