Dance Party2
Dance Party2

Reputation: 7536

MatPlotLib: Control Ind Increments

Given this chart:

import matplotlib.pyplot as plt
plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))

plt.barh(y_pos, performance, align='center', alpha=0.4)

plt.show()

enter image description here You'll notice that the y-axis ind (index?) is in increments of 0.5. However, if I add a person to the list of people and re-run the code, the index is in increments of 1.

Is there any way to control the increments so that they are always in units of 1?

Update

If I can somehow get the increment (0.5 or 1) from the y-axis, that would be just as good.

Upvotes: 0

Views: 358

Answers (1)

Ohad Eytan
Ohad Eytan

Reputation: 8464

Use the yticks function like this:

plt.yticks(range(len(y_pos)))

Upvotes: 1

Related Questions