0

I want to use np.arange() to define axis tick labels. But several labels go out to crazy decimal places (e.g., 0.850000000000000001 instead of 0.85). Using np.around() to 2 decimals does not help either because then the numbers have alternating decimal places (0.45, 0.5, 0.55...). How can I just have it write each tick label to 2 decimals? Also, I'll want to change fontsize for these labels so I need to call ax.set_yticklabels()

x,y = np.arange(0,1,.05), np.arange(0,1,.05)
fig, ax = plt.subplots(1,1)
ax.plot(x,y)
ax.set_yticks(np.arange(0,1,.05))
ax.set_yticklabels(np.arange(0,1,.05))
jklaus
  • 1,194
  • 1
  • 10
  • 16

1 Answers1

0

Just eliminate the ax.set_yticklabels(). You get the desired result without it.

x,y = np.arange(0,1,.05), np.arange(0,1,.05)
fig, ax = plt.subplots(1,1)
ax.plot(x,y)
ax.set_yticks(np.arange(0,1,.05))

enter image description here

You can change the fontsize for your yticklabels as shown here:

plt.rc('ytick', labelsize=8)
x,y = np.arange(0,1,.05), np.arange(0,1,.05)
fig, ax = plt.subplots(1,1)
ax.plot(x,y)
ax.set_yticks(np.arange(0,1,.05))

enter image description here

pakpe
  • 5,391
  • 2
  • 8
  • 23