Sandeep
Sandeep

Reputation: 1247

Custom Yaxis plot in matplotlib python

Let's say if I have Height = [3, 12, 5, 18, 45] and plot my graph then the yaxis will have ticks starting 0 up to 45 with an interval of 5, which means 0, 5, 10, 15, 20 and so on up to 45. Is there a way to define the interval gap (or the step). For example I want the yaxis to be 0, 15, 30, 45 for the same data set.

Upvotes: 0

Views: 41

Answers (2)

William Feirie
William Feirie

Reputation: 644

import matplotlib.pyplot as plt
import numpy as np

plt.plot([3, 12, 5, 18, 45])
plt.yticks(np.arange(0,45+1,15))
plt.show()

Upvotes: 1

Siladittya
Siladittya

Reputation: 1205

This should work

matplotlib.pyplot.yticks(np.arange(start, stop+1, step))

Upvotes: 1

Related Questions