 # [Matplotlib-users] Does xticks start marking from 0 only?

Given the code:

plt.axis([-5, 105, 0, 5]) # x-axis from -5 to 105,
# y-axis from 0 to 5

plt.xticks([10 * i for i in range(11)])

I see xticks only marks from 0, where as the axis starts from -5.

So does xticks only start marking from 0 even though the x-axis starts from -5 ?

Full Code:

from matplotlib import pyplot as plt
from collections import Counter

grades = [83, 95, 91, 87, 70, 0, 85, 82, 100, 67, 73, 77, 0]

# Bucket grades by decile, but put 100 in with the 90s

plt.bar([x + 5 for x in histogram.keys()], # Shift bars right by 5
histogram.values(), # Give each bar its correct height
10, # Give each bar a width of 10
edgecolor=(0, 0, 0)) # Black edges for each bar

plt.axis([-5, 105, 0, 5]) # x-axis from -5 to 105,
# y-axis from 0 to 5

#xticks takes the highest value in the list given and then
plt.xticks([10 * i for i in range(11)]) # x-axis labels at 0, 10, …, 100
plt.xlabel(“Decile”)
plt.ylabel("# of Students")
plt.show()

···

Regards,
Sreyan Chakravarty

When you use `plt.xticks` you are saying “please put ticks at these locations”, thus you will only see ticks at [0, 10, …, 100], independent of what your limits are.

Tom

···

Thomas Caswell
tcaswell@gmail.com