0

enter image description here

Code:

import matplotlib.pyplot as plt
x = [1, 2]
y = [3, 2]
plt.errorbar(x, y, c='red')
plt.scatter(x, y, c='red')
plt.tick_params(rotation = 45)
plt.title("Points")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()

I don't want any float numbers so I just want 1,2,3

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

3 Answers3

0

Use xticks and yticks to modify your the x and y tick labels

for example,

plt.xticks(range(1, 3))
plt.yticks(range(2, 4))

output:

enter image description here

Anyways, your data have very short range (range of 1-3). It gonna be weird if not using float number.

JayPeerachai
  • 3,499
  • 3
  • 14
  • 29
0

You can use matplotlib.ticker.MultipleLocator. MultipleLocator, Ticks and range are a multiple of base; either integer or float.

class matplotlib.ticker.MultipleLocator(base=1.0)

Set a tick on each integer multiple of a base within the view interval.

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

x = [1, 2]
y = [3, 2]
plt.errorbar(x, y, c='red')
plt.scatter(x, y, c='red')
plt.tick_params(rotation = 45)
plt.title("Points")
plt.xlabel("X")
plt.ylabel("Y")

plt.gca().xaxis.set_major_locator(mticker.MultipleLocator(1))
plt.gca().yaxis.set_major_locator(mticker.MultipleLocator(1))
plt.show()

Output:

enter image description here

I'mahdi
  • 23,382
  • 5
  • 22
  • 30
0

You can try using xticks and yticks to set the range of x- and y-axes; here is the full code:

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
x = [1, 2]
y = [3, 2]
plt.errorbar(x, y, c='red')
plt.scatter(x, y, c='red')
plt.tick_params(rotation = 45)
plt.title("Points")
plt.xlabel("X")
plt.ylabel("Y")

plt.xticks(range(1, 3))
plt.yticks(range(3, 4))
plt.show()

enjoy!

Yasser M
  • 654
  • 7
  • 9
  • where did range(1,3) and range(3,5) come from? –  Dec 18 '22 at 18:36
  • This is to get the scale of x- and y-axis runs between(1, 2) and (3, 4) respectively, you could use different integers and run the code to see the difference between figures. – Yasser M Dec 19 '22 at 16:30