mahmood
mahmood

Reputation: 24765

Specifying steps in y-axis of Pandas plot()

I use the following plot function to create a line chart of a Pandas dataframe

row = df.iloc[0].astype(int)
plt.subplot(1, 2, 1)
row.plot(marker='o', fontsize=20, ylabel=yax_label)
plt.show()

Problem is that, the y steps are shown in float (0.5 steps). Is there any way to control that? For example, 3,4,5,6,7 as integers.

enter image description here

Upvotes: 1

Views: 1144

Answers (1)

I'mahdi
I'mahdi

Reputation: 24059

You can use .set_yticks():

(I can't run your code, send an example)

import matplotlib.pyplot as plt

fig, axe = plt.subplots(1, 3, constrained_layout=True)

axe[0].plot(range(10))
axe[0].set_yticks(np.arange(0,10,0.5))

axe[1].plot(range(10))
axe[1].set_yticks(np.arange(0,10))

axe[2].plot(range(10))
axe[2].set_yticks(np.arange(0,10,2))
plt.show()

Output:

enter image description here

Upvotes: 1

Related Questions