Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading